Skip to content

Commit

Permalink
Merge pull request #314 from kbss-cvut/fix/302-fix-login-response-logic
Browse files Browse the repository at this point in the history
login returns reject promise if login response indicates authentication failed
  • Loading branch information
kostobog authored May 20, 2024
2 parents 973c9d8 + 5f4b633 commit c202b46
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/services/userService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export const login = async (loginRequest: UserLoginRequest): Promise<UserLoginRe
const response = await axiosClient.post<UserLoginResponse>("/auth/signin", loginRequest, {
headers: { "Content-type": AUTH },
});

return response.data;
if (response.data.success || response.data.loggedIn) {
return response.data;
}
return Promise.reject(response.data.errorMessage);
} catch (e) {
console.log("Failed to call /login");
const defaultMessage = "Login failed";
return new Promise((resolve, reject) => reject(handleServerError(e, defaultMessage)));
return Promise.reject(handleServerError(e, defaultMessage));
}
};

Expand Down

0 comments on commit c202b46

Please sign in to comment.