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" ;
@@ -18,21 +18,28 @@ export default function ForgotPasswordPage() {
1818
1919 // Validate email domain
2020 if ( ! isAllowedEmail ( email ) ) {
21- addToast ( "Can't Access SORRY " , "error" ) ;
21+ addToast ( "Please enter a valid email address. " , "error" ) ;
2222 setLoading ( false ) ;
2323 return ;
2424 }
2525
2626 try {
27- // Send password reset email
28- // Note: Firebase won't error for non-existent emails (security feature)
27+ // Check if email exists in Firebase Auth
28+ const emailExists = await checkEmailExists ( email ) ;
29+
30+ if ( ! emailExists ) {
31+ addToast ( "We couldn't find an account with this email address." , "error" ) ;
32+ setLoading ( false ) ;
33+ return ;
34+ }
35+
36+ // Email exists - send password reset link
2937 await resetPassword ( email ) ;
30- addToast ( "If an account exists with this email, a password reset link has been sent." , "success" ) ;
31- // Clear the email field after success
32- setEmail ( "" ) ;
38+ addToast ( "Password reset link has been sent to your email." , "success" ) ;
39+ setEmail ( "" ) ; // Clear the email field
3340 } catch ( err : any ) {
3441 console . error ( "Error in handleReset:" , err ) ;
35- addToast ( "Can't reset password . Please try again." , "error" ) ;
42+ addToast ( "Something went wrong . Please try again later ." , "error" ) ;
3643 } finally {
3744 setLoading ( false ) ;
3845 }
0 commit comments