BETTER-AUTH. UI
Mutations

useVerifyTwoFactorOtp

Verify the emailed second-factor code.

Send the code with useSendTwoFactorOtp first. Refetches the session on success.

Usage

import type { TwoFactorAuthClient } from "@better-auth-ui/core/plugins/two-factor"
import { useAuth } from "@better-auth-ui/react"
import { useVerifyTwoFactorOtp } from "@better-auth-ui/react/plugins/two-factor"

const { authClient } = useAuth()
const { mutate: verifyTwoFactorOtp } = useVerifyTwoFactorOtp(
  authClient as TwoFactorAuthClient
)

verifyTwoFactorOtp({ code: "123456", trustDevice: true })

useVerifyTwoFactorOtp requires the Better Auth twoFactor plugin. Cast authClient to TwoFactorAuthClient so TypeScript picks up the plugin-extended method signature.

Options factory

import { verifyTwoFactorOtpOptions } from "@better-auth-ui/core/plugins/two-factor"
import { useMutation } from "@tanstack/react-query"

const { mutate } = useMutation(verifyTwoFactorOtpOptions(authClient))

Params

Prop

Type

Last updated on

On this page