diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index da8b7d4..d36c1cd 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -15,6 +15,9 @@ export default function LoginPage() { const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [userType, setUserType] = useState<'USER' | 'ADMIN'>('USER'); + const [showResendVerification, setShowResendVerification] = useState(false); + const [resendingVerification, setResendingVerification] = useState(false); + const [resendSuccess, setResendSuccess] = useState(''); // Clear logout flags on mount so API calls aren't blocked after redirect from logout useEffect(() => { @@ -27,10 +30,40 @@ export default function LoginPage() { } }, [searchParams]); + const handleResendVerification = async () => { + if (!email) { + setError('Please enter your email first'); + return; + } + setResendingVerification(true); + setResendSuccess(''); + try { + const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/resend-verification-public`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email }), + }); + const data = await res.json(); + if (res.ok) { + setResendSuccess(data?.data?.message || 'Verification email sent. Please check your inbox.'); + setError(''); + setShowResendVerification(false); + } else { + setError(data?.message || 'Failed to resend verification email'); + } + } catch { + setError('Failed to resend verification email'); + } finally { + setResendingVerification(false); + } + }; + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); + setResendSuccess(''); + setShowResendVerification(false); // Clear logout flags now that user is actively logging in localStorage.removeItem('isLoggingOut'); @@ -47,8 +80,12 @@ export default function LoginPage() { const validateData = await validateRes.json(); if (!validateRes.ok) { - // Show the actual error message from backend - setError(validateData.message || 'Invalid email or password'); + const msg = validateData.message || 'Invalid email or password'; + setError(msg); + // If error is about email verification, show resend button + if (msg.toLowerCase().includes('verify your email') || msg.toLowerCase().includes('not verified')) { + setShowResendVerification(true); + } setLoading(false); return; } @@ -144,6 +181,21 @@ export default function LoginPage() { {error && (