Skip to content

Commit 62aa00d

Browse files
committed
Implement explicit email existence check for forgot password (requires disabling Firebase enumeration protection)
1 parent fe691a2 commit 62aa00d

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useState } from "react";
4-
import { resetPassword } from "@/lib/firebase/auth";
4+
import { resetPassword, checkEmailExists } from "@/lib/firebase/auth";
55
import Link from "next/link";
66
import { Mail, ArrowLeft } from "lucide-react";
77
import { useToast } from "@/context/ToastContext";
@@ -24,13 +24,21 @@ export default function ForgotPasswordPage() {
2424
}
2525

2626
try {
27-
// Standard Security Practice:
28-
// We blindly send the reset request. Firebase handles existence checks internally.
29-
// If the user exists, they get an email. If not, nothing happens.
30-
// We always show success to prevent email enumeration attacks and ensure valid users aren't blocked by API protections.
27+
// 1. Check if account exists first
28+
// Note: This requires 'Email Enumeration Protection' to be DISABLED in Firebase Console
29+
const emailExists = await checkEmailExists(email);
30+
31+
if (!emailExists) {
32+
// 2. STOP if account not found
33+
addToast("We couldn't find an account with this email address.", "error");
34+
setLoading(false);
35+
return;
36+
}
37+
38+
// 3. Only send email if account exists
3139
await resetPassword(email);
3240

33-
addToast("If an account exists with this email, a password reset link has been sent.", "success");
41+
addToast("Password reset link has been sent to your email.", "success");
3442
setEmail(""); // Clear form
3543
} catch (err: any) {
3644
console.error("Error in handleReset:", err);

0 commit comments

Comments
 (0)