@@ -8,9 +8,9 @@ import { THEMES } from '../constants';
88import { useAuth } from '../contexts/AuthContext' ;
99import { useTheme } from '../contexts/ThemeContext' ;
1010import {
11- login as apiLogin ,
12- signup as apiSignup ,
13- loginWithGoogle ,
11+ login as apiLogin ,
12+ signup as apiSignup ,
13+ loginWithGoogle ,
1414} from '../services/api' ;
1515import { signInWithGoogle } from '../services/firebase' ;
1616
@@ -34,16 +34,22 @@ export const Auth = () => {
3434 try {
3535 const idToken = await signInWithGoogle ( ) ;
3636 const res = await loginWithGoogle ( idToken ) ;
37- const { access_token, user } = res . data ;
37+ const { access_token, user } = res . data ?? { } ;
38+ if ( ! access_token || ! user ) {
39+ throw new Error ( 'Invalid response from server' ) ;
40+ }
3841 login ( access_token , user ) ;
3942 navigate ( '/dashboard' ) ;
4043 } catch ( err : any ) {
4144 console . error ( 'Google login error:' , err ) ;
4245 if ( err . code === 'auth/popup-closed-by-user' ) {
4346 setError ( '' ) ;
4447 } else if ( err . response ) {
48+ const detail = err . response . data ?. detail ;
4549 setError (
46- err . response . data ?. detail || 'Google authentication failed'
50+ typeof detail === 'string'
51+ ? detail
52+ : detail ?. [ 0 ] ?. msg || 'Google authentication failed'
4753 ) ;
4854 } else {
4955 setError ( err . message || 'Google authentication failed. Please try again.' ) ;
@@ -71,8 +77,11 @@ export const Auth = () => {
7177 navigate ( '/dashboard' ) ;
7278 } catch ( err : any ) {
7379 if ( err . response ) {
80+ const detail = err . response . data ?. detail ;
7481 setError (
75- err . response . data ?. detail ?. [ 0 ] ?. msg || 'Authentication failed'
82+ typeof detail === 'string'
83+ ? detail
84+ : detail ?. [ 0 ] ?. msg || 'Authentication failed'
7685 ) ;
7786 } else {
7887 setError ( 'Something went wrong' ) ;
@@ -161,7 +170,11 @@ export const Auth = () => {
161170 } `}
162171 >
163172 { googleLoading ? (
164- < div className = "w-5 h-5 border-2 border-black/20 border-t-black rounded-full animate-spin" />
173+ < div
174+ className = "w-5 h-5 border-2 border-black/20 border-t-black rounded-full animate-spin"
175+ role = "status"
176+ aria-label = "Signing in with Google"
177+ />
165178 ) : (
166179 < svg className = "w-5 h-5" viewBox = "0 0 24 24" role = "img" aria-labelledby = "google-logo-title" >
167180 < title id = "google-logo-title" > Google logo</ title >
0 commit comments