'use client'; import React, { useState } from 'react'; import Link from 'next/link'; import { Card, CardContent } from '@/components/ui/Card'; import { Input } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { useCsrf } from '@/hooks/useCsrf'; export default function ForgotPasswordPage() { const { fetchWithCsrf, loading: csrfLoading } = useCsrf(); const [email, setEmail] = useState(''); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const response = await fetchWithCsrf('/api/auth/forgot-password', { method: 'POST', body: JSON.stringify({ email }), }); const data = await response.json(); if (response.ok) { setSuccess(true); } else { setError(data.error || 'Failed to send reset email'); } } catch (err) { setError('An error occurred. Please try again.'); } finally { setLoading(false); } }; if (success) { return (
We've sent you a password reset link
We've sent a password reset link to {email}
Please check your email and click the link to reset your password. The link will expire in 1 hour.
No worries, we'll send you reset instructions
Remember your password?{' '} Sign in