fix: Improve email verification with better error handling

- Added fallback verification method using password reset email
- Added detailed error messages for rate limits and user not found
- Added console logging for debugging email send issues
- Improved user feedback with "check spam folder" message

Debug steps:
1. Check browser console for detailed error logs
2. Verify Supabase dashboard settings (Auth > Email)
3. Check email templates are configured
4. Confirm "Confirm email" is enabled in Auth settings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-29 03:45:45 +03:00
parent 4dce9a9298
commit e05fd0234a
+48 -7
View File
@@ -64,25 +64,66 @@ export default function Dashboard() {
};
const sendVerificationEmail = async () => {
if (!user?.email) {
toast({
title: "Error",
description: "No email address found",
variant: "destructive"
});
return;
}
console.log('🔄 Attempting to send verification email to:', user.email);
console.log('🔐 User object:', user);
try {
// Supabase automatically sends verification email when updating email
// or we can trigger resend with updateUser
const { error } = await supabase.auth.resend({
// Method 1: Try resend API
console.log('📧 Trying Supabase auth.resend()...');
const { error: resendError } = await supabase.auth.resend({
type: 'signup',
email: user?.email || '',
email: user.email,
});
if (error) throw error;
if (resendError) {
console.error('❌ Resend error:', resendError);
} else {
console.log('✅ Resend successful');
}
// If resend fails, try alternative method
if (resendError) {
console.warn('Resend failed, trying alternative method:', resendError);
// Method 2: Request password reset as verification alternative
// This will send an email if the account exists
const { error: resetError } = await supabase.auth.resetPasswordForEmail(user.email, {
redirectTo: `${window.location.origin}/email-verification`,
});
if (resetError) throw resetError;
}
toast({
title: "Verification Email Sent",
description: "Please check your email for verification link",
description: "Please check your email inbox and spam folder",
});
} catch (error: any) {
console.error('Error sending verification email:', error);
// Provide more detailed error message
let errorMessage = "Failed to send verification email";
if (error.message?.includes('Email rate limit exceeded')) {
errorMessage = "Too many requests. Please wait a few minutes and try again.";
} else if (error.message?.includes('User not found')) {
errorMessage = "Account not found. Please sign up first.";
} else if (error.message) {
errorMessage = error.message;
}
toast({
title: "Error",
description: error.message || "Failed to send verification email",
description: errorMessage,
variant: "destructive"
});
}