From 5f4b6339fbad3f915c2cd4e247ded4249442ef38 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 17 May 2024 23:40:07 +0200 Subject: [PATCH] login returns reject promise if login response indicates authentication failed --- src/services/userService.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/userService.tsx b/src/services/userService.tsx index 842f42f2..84921535 100644 --- a/src/services/userService.tsx +++ b/src/services/userService.tsx @@ -33,12 +33,14 @@ export const login = async (loginRequest: UserLoginRequest): Promise("/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)); } };