BETTER-AUTH. UI
Mutations

useSendTwoFactorOtp

Email the second-factor code.

Authenticated by the two-factor cookie Better Auth set during sign-in, so it only works while a challenge is pending.

Usage

import {
  type TwoFactorAuthClient,
  useAuth,
  useSendTwoFactorOtp
} from "@better-auth-ui/react"

const { authClient } = useAuth()
const { mutate: sendTwoFactorOtp } = useSendTwoFactorOtp(
  authClient as TwoFactorAuthClient
)

sendTwoFactorOtp()

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

Options factory

import { sendTwoFactorOtpOptions } from "@better-auth-ui/react"
import { useMutation } from "@tanstack/react-query"

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

Params

Prop

Type

Last updated on

On this page