feat: add resend verification button on login screen for unverified users

This commit is contained in:
nmemmert committed 2026-01-16 09:39:56 -05:00
1 parent 7c47901563
commit 302a89e8d8
2 files changed
+49 -2

No files matched your search

+48 -1
View File
@@ -18,6 +18,8 @@ export default function Login() {
const [forgotMessage, setForgotMessage] = useState('');
const [showVerificationBanner, setShowVerificationBanner] = useState(false);
const [verificationSent, setVerificationSent] = useState(false);
const [needsVerification, setNeedsVerification] = useState(false);
const [resendEmail, setResendEmail] = useState('');
const { login, signup, sendPasswordReset, sendVerificationEmailToUser } = useAuth();
const handleSubmit = async (e: React.FormEvent) => {
@@ -61,12 +63,43 @@ export default function Login() {
localStorage.removeItem('rememberMeTimestamp');
}
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'An error occurred');
const errorMessage = err instanceof Error ? err.message : 'An error occurred';
setError(errorMessage);
// Check if error is about email verification
if (errorMessage.includes('verify your email')) {
setNeedsVerification(true);
setResendEmail(email);
}
}
}
setLoading(false);
};
const handleResendVerification = async () => {
setLoading(true);
setError('');
try {
// Try to login temporarily to send verification
const { signInWithEmailAndPassword } = await import('firebase/auth');
const { auth } = await import('@/lib/firebase');
const userCred = await signInWithEmailAndPassword(auth, resendEmail, password);
await sendVerificationEmailToUser(userCred.user);
// Sign them back out
const { signOut } = await import('firebase/auth');
await signOut(auth);
setError('');
setShowVerificationBanner(true);
setVerificationSent(true);
setNeedsVerification(false);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'Failed to resend verification email');
}
setLoading(false);
};
const handleForgotPassword = async () => {
if (!forgotEmail) {
setForgotMessage('Please enter your email address');
@@ -99,6 +132,20 @@ export default function Login() {
{error}
</div>
)}
{needsVerification && (
<div className="bg-yellow-900 border border-yellow-700 text-yellow-200 px-4 py-3 rounded-lg">
<p className="font-semibold mb-2">Email Not Verified</p>
<p className="text-sm mb-3">Please check your inbox for the verification email.</p>
<button
type="button"
onClick={handleResendVerification}
disabled={loading}
className="w-full px-3 py-2 bg-yellow-600 hover:bg-yellow-700 disabled:bg-yellow-800 disabled:cursor-not-allowed text-white text-sm font-medium rounded-lg transition-colors"
>
{loading ? 'Sending...' : 'Resend Verification Email'}
</button>
</div>
)}
{isSignup && (
<div>
<label className="block text-sm font-medium text-gray-300 mb-2">First Name</label>