useVerifyMagicLink
Import
import { useVerifyMagicLink } from '@zerodev/wallet-react'Usage
import { useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import { useAccount } from 'wagmi'
import { useVerifyMagicLink } from '@zerodev/wallet-react'
function VerifyPage() {
const searchParams = useSearchParams()
const verifyMagicLink = useVerifyMagicLink()
const { address, isConnected } = useAccount()
useEffect(() => {
const code = searchParams.get('code')
const otpId = sessionStorage.getItem('magicLinkOtpId')
if (code && otpId && !isConnected) {
verifyMagicLink.mutateAsync({ otpId, code })
}
}, [searchParams])
if (isConnected) return <p>Authenticated: {address}</p>
if (verifyMagicLink.isPending) return <p>Verifying...</p>
if (verifyMagicLink.isError) return <p>Error: {verifyMagicLink.error.message}</p>
return <p>Waiting for verification...</p>
}Parameters
otpId
string
Required. The OTP identifier returned by useSendMagicLink.
code
string
Required. The verification code from the magic link URL query parameters.
Return Types
mutate
(variables: { otpId: string; code: string }) => void
The mutation function to verify the magic link.
mutateAsync
(variables: { otpId: string; code: string }) => Promise<void>
Similar to mutate but returns a promise. Resolves when the magic link 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
trueif the mutation has beenpaused. - 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).