'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Link2, Mail } from 'lucide-react' import Link from 'next/link' import { toast } from 'sonner' export function ForgotPasswordClient() { const [email, setEmail] = useState('') const [loading, setLoading] = useState(false) const [sent, setSent] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) try { const res = await fetch('/api/password/forgot', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email }), }) const data = await res.json() if (res.ok) { // The server answer is deliberately identical for every address // (no account enumeration), so the UI must not claim more than // "if the account exists, a link is on its way". setSent(true) } else { toast.error(data?.error ?? 'Could not send the reset link') } } catch { toast.error('Could not send the reset link') } setLoading(false) } return (
{sent ? 'If that email has an account, a reset link is on its way. Check your inbox.' : 'Enter your account email and we will send you a reset link.'}
Remembered it? Back to sign in