Skip to content

useLoginPasskey

Hook for logging in with an existing passkey

Import

import { useLoginPasskey } from '@zerodev/wallet-react'

Usage

import { useLoginPasskey } from '@zerodev/wallet-react'
import { useAccount } from 'wagmi'
 
function Login() {
  const loginPasskey = useLoginPasskey()
  const { address, isConnected } = useAccount()
 
  if (isConnected) {
    return <p>Logged in: {address}</p>
  }
 
  return (
    <button
      onClick={() => loginPasskey.mutateAsync()}
      disabled={loginPasskey.isPending}
    >
      {loginPasskey.isPending ? 'Logging in...' : 'Login with Passkey'}
    </button>
  )
}

Parameters

This hook takes no mutation variables. It triggers the browser's WebAuthn prompt to authenticate with an existing passkey.

Return Types

TanStack Query mutation docs

mutate

() => void

The mutation function to log in with a passkey. Triggers the WebAuthn browser prompt.

mutateAsync

() => Promise<void>

Similar to mutate but returns a promise. Resolves when the passkey is verified and the wallet is connected.

data

void

This mutation does not return data. On success, the Wagmi connector is connected and the account is available via useAccount.

error

Error | null

The error object for the mutation, if an error was encountered.

isError / isIdle / isPending / isSuccess

boolean

Boolean variables derived from status.

isPaused

boolean

  • will be true if the mutation has been paused.
  • see Network Mode for more information.

status

'idle' | 'pending' | 'error' | 'success'

  • 'idle' initial status prior to the mutation function executing.
  • 'pending' if the mutation is currently executing.
  • 'error' if the last mutation attempt resulted in an error.
  • 'success' if the last mutation attempt was successful.

reset

() => void

A function to clean the mutation internal state (e.g. it resets the mutation to its initial state).