src/examples/tour/link.ts

Every source

src/examples/tour/link.ts
'use client'

import { type SignInMethod, useAuth, useLinkedAccounts } from '@synqauth/react'
import { useConnectedWallet } from '@synqauth/solana/react'

// A second way in (AERO-3484, the tour's second step): one person, one
// account, as many ways in as they like, so a lost wallet is never a lost
// account. Synq asks them to confirm it's them first when their sign-in
// isn't recent, then for the new way, and comes back to `returnTo`.
// Another wallet joins with one signature and no page.

export function useAddAWayIn(returnTo: string) {
  const { link, passkeys } = useAuth()
  const { data: ways, isLoading, reload } = useLinkedAccounts()
  const connected = useConnectedWallet()

  return {
    ways: ways ?? [],
    isLoading,
    reload,
    add: (method: SignInMethod) => link(method, { returnTo }),
    /** Confirming it's them opens on the way they signed in (AERO-3537), not another. */
    addPasskey: (signedInWith?: string | null) =>
      passkeys.add({ returnTo, ...(signedInWith ? { method: signedInWith as SignInMethod } : {}) }),
    /** The wallet connected now, when it isn't on the account yet: one signature adds it. */
    addConnectedWallet: () => connected.addToProfile(),
  }
}