@@ -30,7 +30,11 @@ export interface AuthResult {
3030 errorCode ?: string ;
3131}
3232
33- const login = async ( email : string , password : string , isAdminPortal : boolean = false ) : Promise < AuthResult > => {
33+ const login = async (
34+ email : string ,
35+ password : string ,
36+ isAdminPortal : boolean = false ,
37+ ) : Promise < AuthResult > => {
3438 try {
3539 // Validate inputs
3640 if ( ! validateEmail ( email ) ) {
@@ -59,28 +63,30 @@ const login = async (email: string, password: string, isAdminPortal: boolean = f
5963 try {
6064 const loginRequest : LoginRequest = { email, password } ;
6165 const headers : any = { withCredentials : true } ;
62-
66+
6367 // Add admin portal header if this is an admin login
6468 if ( isAdminPortal ) {
6569 headers . headers = { 'X-Admin-Portal' : 'true' } ;
6670 }
67-
71+
6872 const { data } = await baseAPIClient . post < AuthResponse > ( '/auth/login' , loginRequest , headers ) ;
6973 localStorage . setItem ( AUTHENTICATED_USER_KEY , JSON . stringify ( data ) ) ;
7074 return { success : true , user : { ...data . user , ...data } } ;
7175 } catch ( error ) {
7276 // Handle admin privilege errors specifically
7377 if ( error && typeof error === 'object' && 'response' in error ) {
74- const response = ( error as { response ?: { status ?: number ; data ?: { detail ?: string } } } ) . response ;
78+ const response = ( error as { response ?: { status ?: number ; data ?: { detail ?: string } } } )
79+ . response ;
7580 if ( response ?. status === 403 && isAdminPortal ) {
7681 return {
7782 success : false ,
78- error : 'Access denied. You do not have admin privileges. Please contact an administrator.' ,
83+ error :
84+ 'Access denied. You do not have admin privileges. Please contact an administrator.' ,
7985 errorCode : 'auth/insufficient-privileges' ,
8086 } ;
8187 }
8288 }
83-
89+
8490 // Backend login failure is not critical since Firebase auth succeeded
8591 return {
8692 success : true ,
0 commit comments