Mutations
useGenerateBackupCodes
Replace the existing backup codes.
The new codes are returned once. Keep them in component state and let the user copy them: they are never returned again.
Usage
import type { TwoFactorAuthClient } from "@better-auth-ui/core/plugins/two-factor"
import { useAuth } from "@better-auth-ui/react"
import { useGenerateBackupCodes } from "@better-auth-ui/react/plugins/two-factor"
const { authClient } = useAuth()
const { mutate: generateBackupCodes } = useGenerateBackupCodes(
authClient as TwoFactorAuthClient
)
generateBackupCodes({ password: "current-password" })useGenerateBackupCodes requires the Better Auth twoFactor plugin. Cast authClient to TwoFactorAuthClient so TypeScript picks up the plugin-extended method signature.
Options factory
import { generateBackupCodesOptions } from "@better-auth-ui/core/plugins/two-factor"
import { useMutation } from "@tanstack/react-query"
const { mutate } = useMutation(generateBackupCodesOptions(authClient))Params
Prop
Type
Last updated on