Mutations
useEnableTwoFactor
Start two-factor enrollment.
Resolves with the TOTP URI and the backup codes. Unless the server sets skipVerificationOnEnable, two-factor only becomes active once useVerifyTotp succeeds.
Usage
import type { TwoFactorAuthClient } from "@better-auth-ui/core/plugins/two-factor"
import { useAuth } from "@better-auth-ui/react"
import { useEnableTwoFactor } from "@better-auth-ui/react/plugins/two-factor"
const { authClient } = useAuth()
const { mutate: enableTwoFactor } = useEnableTwoFactor(
authClient as TwoFactorAuthClient
)
enableTwoFactor(
{ password: "current-password" },
{
onSuccess: ({ totpURI, backupCodes }) => {
// Render the QR code and show the backup codes once.
}
}
)useEnableTwoFactor requires the Better Auth twoFactor plugin. Cast authClient to TwoFactorAuthClient so TypeScript picks up the plugin-extended method signature.
Options factory
import { enableTwoFactorOptions } from "@better-auth-ui/core/plugins/two-factor"
import { useMutation } from "@tanstack/react-query"
const { mutate } = useMutation(enableTwoFactorOptions(authClient))Params
Prop
Type
Last updated on