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 (
{/* Navigation */} {/* Form */}

Reset your password

{submitted ? "Check your email for a reset link" : "Enter your email and we'll send you a reset link"}

{submitted ? (

If an account exists for {email}, you'll receive an email with instructions.

) : (
setEmail(e.target.value)} placeholder="you@example.com" required className="w-full px-3 py-2 border border-border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" />

Remember your password?{" "}

)}
); }