'use client'; import { useActionState, useState } from 'react'; import { changePasswordAction, confirmMfaSetupAction, disableMfaAction, regenerateRecoveryCodesAction, startMfaSetupAction } from '@/lib/auth/account-actions'; import { idle } from '@/lib/auth/state'; import { CodeInput, Field, FormMessage, PasswordField, SubmitButton, TextInput } from '@/components/account/form'; export function ChangePasswordForm() { const [state, action] = useActionState(changePasswordAction, idle); return (
Change password

Changing your password signs out every other session.

); } function RecoveryCodes({ codes }: { codes: string[] }) { const [copied, setCopied] = useState(false); return (

Recovery codes — shown once. Store them somewhere safe.

    {codes.map((c) => (
  • {c}
  • ))}
Download .txt
); } export function MfaSection({ enabled }: { enabled: boolean }) { const [start, startAction] = useActionState(startMfaSetupAction, idle); const [confirm, confirmAction] = useActionState(confirmMfaSetupAction, idle); const [disable, disableAction] = useActionState(disableMfaAction, idle); const [regen, regenAction] = useActionState(regenerateRecoveryCodesAction, idle); const [showDisable, setShowDisable] = useState(false); const [showRegen, setShowRegen] = useState(false); const codes = (confirm.data?.recoveryCodes as string[] | undefined) ?? (regen.data?.recoveryCodes as string[] | undefined); if (confirm.ok && codes) { return (
); } if (!enabled) { if (start.ok && start.data) { return (
{/* eslint-disable-next-line @next/next/no-img-element */} Authenticator QR code

1. Open your authenticator (1Password, Google Authenticator, Authy, iCloud Keychain…).

2. Scan the QR code, or enter this key manually:

{String(start.data.secret)}

3. Enter the 6-digit code it shows.

Enable authenticator ); } return (

Time-based codes from an authenticator app, plus 10 single-use recovery codes. E-mail codes remain available as a fallback.

Set up authenticator ); } return (
{regen.ok && codes ? : null}
{showRegen ? (
Generate 10 new codes
) : null} {showDisable ? (
Disable two-step authenticator ) : null}
); }