import { useState } from "react"; import toast from "react-hot-toast"; import { MdOutlineEmail } from "react-icons/md"; import { useAuth } from "../AuthContext"; import InputField from "./InputField"; import Spinner from "./Spinner"; /** * ForgotPassword — standalone screen inside the auth card. * Shown when the user clicks "Forgot Password?" on the login form. * onBack() returns to sign-in. */ export default function ForgotPassword({ onBack }) { const { forgotPassword } = useAuth(); const [email, setEmail] = useState(""); const [loading, setLoading] = useState(false); const [sent, setSent] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); const normalized = email.trim(); if (!normalized) { toast.error("Please enter your email address."); return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized)) { toast.error("Please enter a valid email address."); return; } setLoading(true); const { error } = await forgotPassword(normalized); setLoading(false); if (error) { toast.error("Could not send the reset link. Please try again."); } else { setSent(true); toast.success("Reset link sent — check your inbox."); } }; return (
{/* Back link */}

Reset your password

Enter the email linked to your account and we'll send you a reset link.

{sent ? (
✉️

A reset link was sent to {email.trim()}.
Check your inbox (and spam folder, just in case).

) : (
setEmail(e.target.value)} placeholder="you@example.com" autoComplete="email" icon={} /> )}
); }