11"use client" ;
22
33import { useState } from "react" ;
4- import { resetPassword } from "@/lib/firebase/auth" ;
4+ import { resetPassword , checkEmailExists } from "@/lib/firebase/auth" ;
55import Link from "next/link" ;
66import { Mail , ArrowLeft } from "lucide-react" ;
77import { 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