"use client" import { FormEvent, useState } from "react" import AuthShell from "../components/AuthShell" export default function ForgotPasswordPage() { const [recoveryToken, setRecoveryToken] = useState("") const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [message, setMessage] = useState("") const [busy, setBusy] = useState(false) const submit = async (event: FormEvent) => { event.preventDefault() setMessage("") if (password !== confirmPassword) { setMessage("Passwords do not match.") return } setBusy(true) try { const response = await fetch("/api/auth/recover", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ recoveryToken, password }), }) const data = await response.json() if (!response.ok) throw new Error(data.error || "Could not reset password.") setMessage("Password reset. Redirecting...") window.setTimeout(() => { window.location.href = "/" }, 600) } catch (error) { setMessage(error instanceof Error ? error.message : "Could not reset password.") } finally { setBusy(false) } } return (
{message && (
{message}
)} Back to Sign In
) }