File tree Expand file tree Collapse file tree
SparkyFitnessFrontend/src/api/Auth Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export const registerUser = async (
5858 throw error ;
5959 }
6060
61- const authData = data as BetterAuthResponse | null ;
61+ const authData = data as Partial < BetterAuthResponse > | null ;
6262
6363 if ( ! authData ?. user ) {
6464 throw new Error (
@@ -90,15 +90,9 @@ export const loginUser = async (
9090 throw error ;
9191 }
9292
93- const authData = data as BetterAuthResponse | null ;
93+ const authData = data as Partial < BetterAuthResponse > | null ;
9494
95- if ( ! authData ?. user ) {
96- throw new Error (
97- 'Login succeeded but no user data was received from the server.'
98- ) ;
99- }
100-
101- // Better Auth native 2FA handling
95+ // Better Auth native 2FA handling - Check this BEFORE checking for user data
10296 if ( authData ?. twoFactorRedirect ) {
10397 return {
10498 userId : authData ?. user ?. id || '' ,
@@ -110,6 +104,12 @@ export const loginUser = async (
110104 } as AuthResponse ;
111105 }
112106
107+ if ( ! authData ?. user ) {
108+ throw new Error (
109+ 'Login succeeded but no user data was received from the server.'
110+ ) ;
111+ }
112+
113113 return {
114114 message : 'Login successful' ,
115115 userId : authData ?. user ?. id ,
You can’t perform that action at this time.
0 commit comments