import { useState } from "react"; import { toast } from "sonner"; import { ThemeToggle } from "../components/ThemeToggle"; import { Button } from "../components/ui/button"; import { authClient } from "../lib/auth-client"; interface ForgotPasswordPageProps { navigate: ( route: | "/" | "/login" | "/signup" | "/pricing" | "/dashboard" | "/forgot-password" | "/reset-password", ) => void; } export default function ForgotPasswordPage({ navigate }: ForgotPasswordPageProps) { const [email, setEmail] = useState(""); const [isLoading, setIsLoading] = useState(false); const [submitted, setSubmitted] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); try { const result = await authClient.requestPasswordReset({ email, redirectTo: `${window.location.origin}/#/reset-password`, }); if (result.error) { toast.error("Failed to send reset email", { description: result.error.message || "Please try again.", }); setIsLoading(false); return; } setSubmitted(true); toast.success("Reset email sent", { description: "Check your inbox for the reset link.", }); } catch (err) { toast.error("An unexpected error occurred"); } setIsLoading(false); }; return (
{submitted ? "Check your email for a reset link" : "Enter your email and we'll send you a reset link"}
If an account exists for {email}, you'll receive an email with instructions.