import { type FormEvent, useState } from "react"; import { Link } from "react-router-dom"; import { authClient } from "./auth-client.ts"; // /forgot-password — request a password reset email. Better Auth's // requestPasswordReset endpoint deliberately returns the same "if this email // exists" message whether or not the address is on file, so we mirror that in // the UI and just confirm the email was sent. The user clicks the link in the // email, lands on /reset-password?token=… (after BA validates the token), // where they enter a new password. export function ForgotPassword() { const [email, setEmail] = useState(""); const [submitting, setSubmitting] = useState(false); const [sent, setSent] = useState(false); const [error, setError] = useState(null); async function onSubmit(e: FormEvent) { e.preventDefault(); setError(null); if (!/.+@.+\..+/.test(email)) { setError("Enter a valid email address."); return; } setSubmitting(true); try { const result = await authClient.requestPasswordReset({ email, redirectTo: `${window.location.origin}/reset-password`, }); if (result.error) { setError(result.error.message ?? "Couldn't send reset email."); return; } setSent(true); } catch (err) { setError(err instanceof Error ? err.message : "Unexpected error"); } finally { setSubmitting(false); } } return (

{sent ? "Check your email" : "Reset your password"}

{sent ? `If an account exists for ${email}, we've sent a link to reset your password.` : "Enter the email you signed up with and we'll send you a reset link."}

{sent ? (
Back to sign in
) : (
setEmail(ev.target.value)} className={inputClass} autoComplete="username" /> {error &&

{error}

} Send reset link
← Back to sign in
)}
); } function Shell({ children }: { children: React.ReactNode }) { return (
{children}
); } const inputClass = "h-11 w-full rounded-[8px] border border-border bg-surface-2 px-3.5 text-[14px] text-fg placeholder:text-subtle focus:border-border-strong focus:outline-none"; function Field({ label, children }: { label: string; children: React.ReactNode }) { return ( ); } function PrimaryButton({ type = "button", loading, children, }: { type?: "button" | "submit"; loading?: boolean; children: React.ReactNode; }) { return ( ); }