@@ -3,19 +3,64 @@ import logo from "../assets/logo.png";
33import "./Login.css" ;
44
55export default function Login ( ) {
6- const [ email , setEmail ] = useState ( "" ) ;
6+ const [ username , setUsername ] = useState ( "" ) ;
77 const [ password , setPassword ] = useState ( "" ) ;
8+ const [ loading , setLoading ] = useState ( false ) ;
89
9- const handleSubmit = ( e ) => {
10+ // ✅ TEMP ADMIN LOGIN (for testing)
11+ const ADMIN_ID = "[email protected] " ; 12+ const ADMIN_PASS = "Admin@123" ;
13+
14+ const handleSubmit = async ( e ) => {
1015 e . preventDefault ( ) ;
11- // Replace this with your backend API call later
12- if ( email === "[email protected] " && password === "password123" ) { 16+ setLoading ( true ) ;
17+
18+ // ✅ Step 1: Local hardcoded admin check (for testing)
19+ if ( username === ADMIN_ID && password === ADMIN_PASS ) {
20+ alert ( "Admin login successful!" ) ;
21+ localStorage . setItem ( "role" , "admin" ) ;
1322 window . location . href = "/dashboard" ;
14- } else {
15- alert ( "Invalid credentials" ) ;
23+ setLoading ( false ) ;
24+ return ;
25+ }
26+
27+ // ✅ Step 2: (optional) Try backend login if not admin
28+ try {
29+ const response = await fetch (
30+ "https://fat-eibl-backend.onrender.com/users/login" ,
31+ {
32+ method : "POST" ,
33+ headers : { "Content-Type" : "application/json" } ,
34+ body : JSON . stringify ( { username, password } ) ,
35+ }
36+ ) ;
37+
38+ const data = await response . json ( ) ;
39+
40+ if ( response . ok ) {
41+ localStorage . setItem ( "token" , data . access_token ) ;
42+ localStorage . setItem ( "role" , data . role ) ;
43+
44+ if ( data . role === "admin" ) {
45+ window . location . href = "/dashboard" ;
46+ } else {
47+ window . location . href = "/user-dashboard" ;
48+ }
49+ } else {
50+ alert ( data . detail || "Invalid username or password" ) ;
51+ }
52+ } catch ( error ) {
53+ console . error ( "Login failed:" , error ) ;
54+ alert ( "Server error. Please try again later." ) ;
55+ } finally {
56+ setLoading ( false ) ;
1657 }
1758 } ;
1859
60+ const handleForgotPassword = ( ) => {
61+ alert ( "Forgot Password feature coming soon. Please contact Admin." ) ;
62+ } ;
63+
1964 return (
2065 < div
2166 style = { {
@@ -27,7 +72,11 @@ export default function Login() {
2772 backgroundColor : "#f5f9ff" ,
2873 } }
2974 >
30- < img src = { logo } alt = "Company Logo" style = { { width : "120px" , marginBottom : "20px" } } />
75+ < img
76+ src = { logo }
77+ alt = "Company Logo"
78+ style = { { width : "120px" , marginBottom : "20px" } }
79+ />
3180 < h1 style = { { color : "#004aad" } } > Welcome to FAT-EIBL</ h1 >
3281 < p style = { { color : "#003b80" , marginBottom : "30px" } } >
3382 Finance Audit Tracker – Edme Insurance Brokers Limited
@@ -45,10 +94,10 @@ export default function Login() {
4594 } }
4695 >
4796 < input
48- type = "email "
49- placeholder = "Email"
50- value = { email }
51- onChange = { ( e ) => setEmail ( e . target . value ) }
97+ type = "text "
98+ placeholder = "Enter Username / Email"
99+ value = { username }
100+ onChange = { ( e ) => setUsername ( e . target . value ) }
52101 style = { {
53102 width : "100%" ,
54103 padding : "10px" ,
@@ -60,7 +109,7 @@ export default function Login() {
60109 />
61110 < input
62111 type = "password"
63- placeholder = "Password"
112+ placeholder = "Enter Password"
64113 value = { password }
65114 onChange = { ( e ) => setPassword ( e . target . value ) }
66115 style = { {
@@ -72,6 +121,7 @@ export default function Login() {
72121 } }
73122 required
74123 />
124+
75125 < button
76126 type = "submit"
77127 style = { {
@@ -83,9 +133,22 @@ export default function Login() {
83133 cursor : "pointer" ,
84134 width : "100%" ,
85135 } }
136+ disabled = { loading }
86137 >
87- Login
138+ { loading ? "Logging in..." : " Login" }
88139 </ button >
140+
141+ < p
142+ onClick = { handleForgotPassword }
143+ style = { {
144+ color : "#004aad" ,
145+ marginTop : "15px" ,
146+ cursor : "pointer" ,
147+ textDecoration : "underline" ,
148+ } }
149+ >
150+ Forgot Password?
151+ </ p >
89152 </ form >
90153 </ div >
91154 ) ;
0 commit comments