"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { authApi } from "@/lib/api"; import { toast } from "@/stores/ui-store"; import { Field, FormError, Input, SubmitButton } from "@/components/ui/form"; type Step = "request" | "confirm" | "done"; export default function ResetPasswordPage() { const router = useRouter(); const [step, setStep] = useState("request"); const [email, setEmail] = useState(""); const [code, setCode] = useState(""); const [password, setPassword] = useState(""); const [password2, setPassword2] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const requestCode = async () => { setError(null); if (!email.trim()) { setError("Enter the email you registered with."); return; } setBusy(true); try { // Always report success (we exist) to avoid account enumeration. await authApi.resetRequest(email.trim()); setStep("confirm"); } catch (err) { setError(err instanceof Error ? err.message : "Could not send the reset code."); } finally { setBusy(false); } }; const confirmReset = async () => { setError(null); if (!code.trim()) return setError("Enter the 6-digit code from the email."); if (password.length < 10) return setError("Password must be at least 10 characters."); if (password !== password2) return setError("Passwords do not match."); setBusy(true); try { await authApi.resetConfirm(email.trim(), code.trim(), password); toast("success", "Password updated", "Sign in with your new password."); setStep("done"); } catch (err) { setError(err instanceof Error ? err.message : "Reset failed. Check the code and try again."); } finally { setBusy(false); } }; return (

Reset password

{step === "request" && "We'll email you a one-time code."} {step === "confirm" && `Enter the code sent to ${email || "your email"} and choose a new password.`} {step === "done" && "Your password has been reset."}

{step === "request" && (
{ e.preventDefault(); void requestCode(); }} > setEmail(e.target.value)} /> Send reset code
)} {step === "confirm" && (
{ e.preventDefault(); void confirmReset(); }} > setCode(e.target.value)} /> setPassword(e.target.value)} /> setPassword2(e.target.value)} /> Reset password
)} {step === "done" && ( )}

Back to sign in

); }