"use client"; import { useState } from "react"; import Link from "next/link"; import { Code2, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; export default function ForgotPasswordPage() { const [email, setEmail] = useState(""); const [loading, setLoading] = useState(false); const [submitted, setSubmitted] = useState(false); const [error, setError] = useState(""); const emailValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(""); if (!emailValid) { setError("Please enter a valid email address"); return; } setLoading(true); try { const res = await fetch("/api/auth/forgot-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }) }); if (!res.ok) { const data: { error?: string } = await res.json(); setError(data.error ?? "Something went wrong"); setLoading(false); return; } setSubmitted(true); } catch { setError("Something went wrong."); setLoading(false); } } if (submitted) { return (

Check your email

If an account exists for that email, we sent a password reset link. It expires in 1 hour.

Back to sign in

); } return (

Reset your password

Enter your email and we'll send you a reset link

setEmail(e.target.value)} placeholder="you@example.com" className={cn("w-full px-3 py-2.5 bg-neutral-950 border rounded-lg text-sm text-neutral-100 placeholder-neutral-500 outline-none transition-colors", email && !emailValid ? "border-red-500/50 focus:border-red-500" : "border-neutral-800 focus:border-blue-500")} /> {email && !emailValid &&

Please enter a valid email address

}
{error && (

{error}

)}

Remember your password?{" "}Sign in

); }