Skip to content

Commit fce8d24

Browse files
author
Simon
committed
fix(auth): check if user exists before returning response
1 parent 40e06fa commit fce8d24

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • SparkyFitnessFrontend/src/api/Auth

SparkyFitnessFrontend/src/api/Auth/auth.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export const registerUser = async (
6464

6565
const authData = data as BetterAuthResponse | null;
6666

67+
if (!authData?.user) {
68+
throw new Error(
69+
'Registration succeeded but no user data was received from the server.'
70+
);
71+
}
72+
6773
return {
6874
message: 'User registered successfully',
6975
userId: authData?.user?.id,
@@ -89,6 +95,13 @@ export const loginUser = async (
8995
}
9096

9197
const authData = data as BetterAuthResponse | null;
98+
99+
if (!authData?.user) {
100+
throw new Error(
101+
'Registration succeeded but no user data was received from the server.'
102+
);
103+
}
104+
92105
// Better Auth native 2FA handling
93106
if (authData?.twoFactorRedirect) {
94107
return {

0 commit comments

Comments
 (0)