import { useEffect, useState } from "react"; import { KeyRound, MailWarning, Sparkles } from "lucide-react"; import { api } from "../lib/api.ts"; import { Button, CopyButton, FlowerMark, Spinner } from "./ui.tsx"; type State = | { kind: "loading" } | { kind: "invalid" } | { kind: "ready"; username: string } | { kind: "working" } | { kind: "done"; key: string } | { kind: "error"; message: string }; /** Public one-time key reset page: /reset/:token */ export function ResetPage({ token }: { token: string }) { const [state, setState] = useState({ kind: "loading" }); useEffect(() => { api.resetCheck(token) .then((r) => setState({ kind: "ready", username: r.username })) .catch(() => setState({ kind: "invalid" })); }, [token]); async function consume() { setState({ kind: "working" }); try { const r = await api.resetConsume(token); setState({ kind: "done", key: r.key }); } catch (err) { setState({ kind: "error", message: err instanceof Error ? err.message : "Reset failed" }); } } return (
{state.kind === "loading" &&

Checking link…

} {state.kind === "invalid" && (

Link invalid

This reset link is unknown, already used, or expired. Request a new one from the login page.

)} {state.kind === "ready" && (

Reset key for @{state.username}?

This issues a fresh access key immediately. Your old key stops working.

)} {state.kind === "working" &&

Issuing…

} {state.kind === "done" && (

New key ready

Copy it now — it won't be shown again. Then log in with it.

{state.key}
)} {state.kind === "error" && (

Reset failed

{state.message}

)}
); }