Skip to content

Commit a20afda

Browse files
authored
Merge pull request #840 from CodeWithCJ/dev
fix for MFA & TOTP code
2 parents 5c5913e + eeedfce commit a20afda

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • SparkyFitnessFrontend/src/api/Auth

SparkyFitnessFrontend/src/api/Auth/auth.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)