"use client"; import { useState } from "react"; import Link from "next/link"; import { Activity, 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. Please try again."); setLoading(false); } } if (submitted) { return (
If an account exists for that email, we sent a password reset link. It expires in 1 hour.
Back to sign in
Enter your email and we'll send you a reset link
Remember your password?{" "} Sign in