Skip to content

Commit a56414b

Browse files
committed
Add detailed logging for email existence validation debugging
1 parent fd99d9f commit a56414b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/app/auth/forgot-password/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@ export default function ForgotPasswordPage() {
2424
}
2525

2626
try {
27+
console.log("Checking if email exists:", email);
2728
// Check if email exists
2829
const emailExists = await checkEmailExists(email);
30+
console.log("Email exists result:", emailExists);
2931

3032
if (!emailExists) {
33+
console.log("Email does not exist, showing error");
3134
addToast("No account found with this email address.", "error");
3235
setLoading(false);
3336
return;
3437
}
3538

39+
console.log("Email exists, sending password reset");
3640
// Send password reset email
3741
await resetPassword(email);
3842
addToast("Password reset email sent! Check your inbox.", "success");
3943
} catch (err: any) {
44+
console.error("Error in handleReset:", err);
4045
addToast("Can't reset password. Please try again.", "error");
41-
console.error(err);
4246
} finally {
4347
setLoading(false);
4448
}

src/lib/firebase/auth.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ export const signOut = () => firebaseSignOut(auth);
6464
export const checkEmailExists = async (email: string): Promise<boolean> => {
6565
try {
6666
const methods = await fetchSignInMethodsForEmail(auth, email);
67-
return methods.length > 0;
68-
} catch (error) {
67+
console.log(`Email ${email} check - Sign-in methods:`, methods);
68+
const exists = methods.length > 0;
69+
console.log(`Email ${email} exists:`, exists);
70+
return exists;
71+
} catch (error: any) {
6972
console.error("Error checking email:", error);
73+
// If error code is auth/invalid-email, the email format is wrong
74+
if (error.code === 'auth/invalid-email') {
75+
return false;
76+
}
77+
// For other errors, assume email doesn't exist to be safe
7078
return false;
7179
}
7280
};

0 commit comments

Comments
 (0)