"use client";
import { useActionState, type ReactNode } from "react";
import {
cancelTwoFactorSetupAction,
disableTwoFactorAction,
enableTwoFactorAction,
regenerateRecoveryCodesAction,
} from "@/app/actions/settings";
import { DownloadIcon } from "@/components/icons";
import { CopyIconButton, TextField } from "@/components/settings-fields";
import { PlateBody, PlateFooter } from "@/components/settings-plate";
import { Alert, Button } from "@/components/ui";
function CodeField({ label = "Authentication code", description }: { label?: string; description?: ReactNode }) {
return (
);
}
/** Recovery codes, shown once: copy, download, then Done reloads the page. */
function RecoveryCodes({ codes, notice }: { codes: string[]; notice: string }) {
const text = codes.join("\n");
const download = () => {
const url = URL.createObjectURL(new Blob([`${text}\n`], { type: "text/plain" }));
const a = Object.assign(document.createElement("a"), { href: url, download: "recovery-codes.txt" });
a.click();
URL.revokeObjectURL(url);
};
return (
<>
{notice}
Save these recovery codes somewhere safe, like a password manager. If you lose your device, each one signs you in once.
You won’t be able to see them again.