33import { useState } from "react" ;
44import { resetPassword } from "@/lib/firebase/auth" ;
55import Link from "next/link" ;
6- import { Mail , ArrowLeft } from "lucide-react" ;
6+ import { Mail , ArrowLeft , AlertTriangle , CheckCircle } from "lucide-react" ;
7+ import { useToast } from "@/context/ToastContext" ;
8+ import { isAllowedEmail } from "@/lib/config" ;
79
810export default function ForgotPasswordPage ( ) {
911 const [ email , setEmail ] = useState ( "" ) ;
1012 const [ message , setMessage ] = useState ( "" ) ;
1113 const [ error , setError ] = useState ( "" ) ;
1214 const [ loading , setLoading ] = useState ( false ) ;
15+ const { addToast } = useToast ( ) ;
1316
1417 const handleReset = async ( e : React . FormEvent ) => {
1518 e . preventDefault ( ) ;
1619 setLoading ( true ) ;
1720 setError ( "" ) ;
1821 setMessage ( "" ) ;
1922
23+ // Validate email domain
24+ if ( ! isAllowedEmail ( email ) ) {
25+ const msg = "Invalid email domain. Please use your institutional email." ;
26+ setError ( msg ) ;
27+ addToast ( msg , "error" ) ;
28+ setLoading ( false ) ;
29+ return ;
30+ }
31+
2032 try {
2133 await resetPassword ( email ) ;
22- setMessage ( "Password reset email sent! Check your inbox." ) ;
34+ const msg = "Password reset email sent! Check your inbox." ;
35+ setMessage ( msg ) ;
36+ addToast ( msg , "success" ) ;
2337 } catch ( err : any ) {
24- setError ( "Failed to send reset email. Check if the address is correct." ) ;
38+ const msg = "Can't reset password. Please check the email and try again." ;
39+ setError ( msg ) ;
40+ addToast ( msg , "error" ) ;
2541 console . error ( err ) ;
2642 } finally {
2743 setLoading ( false ) ;
@@ -43,13 +59,37 @@ export default function ForgotPasswordPage() {
4359 </ p >
4460
4561 { message && (
46- < div style = { { background : "#dcfce7" , color : "#166534" , padding : "0.75rem" , borderRadius : "0.5rem" , marginBottom : "1rem" , fontSize : "0.9rem" } } >
62+ < div style = { {
63+ background : "#dcfce7" ,
64+ color : "#166534" ,
65+ padding : "0.75rem" ,
66+ borderRadius : "0.5rem" ,
67+ marginBottom : "1rem" ,
68+ fontSize : "0.9rem" ,
69+ display : "flex" ,
70+ alignItems : "center" ,
71+ gap : "0.5rem" ,
72+ border : "1px solid #bbf7d0"
73+ } } >
74+ < CheckCircle size = { 18 } />
4775 { message }
4876 </ div >
4977 ) }
5078
5179 { error && (
52- < div style = { { background : "#fee2e2" , color : "#991b1b" , padding : "0.75rem" , borderRadius : "0.5rem" , marginBottom : "1rem" , fontSize : "0.9rem" } } >
80+ < div style = { {
81+ background : "#fee2e2" ,
82+ color : "#991b1b" ,
83+ padding : "0.75rem" ,
84+ borderRadius : "0.5rem" ,
85+ marginBottom : "1rem" ,
86+ fontSize : "0.9rem" ,
87+ display : "flex" ,
88+ alignItems : "center" ,
89+ gap : "0.5rem" ,
90+ border : "1px solid #f87171"
91+ } } >
92+ < AlertTriangle size = { 18 } />
5393 { error }
5494 </ div >
5595 ) }
0 commit comments