diff --git a/public/public/assets/css/style.css b/public/public/assets/css/style.css index ae93f6ba..f1e742ba 100644 --- a/public/public/assets/css/style.css +++ b/public/public/assets/css/style.css @@ -1732,3 +1732,7 @@ section { display: contents; cursor: pointer; } + +.error-text { + color: #ff0000; +} \ No newline at end of file diff --git a/public/src/api/makeApiRequest.ts b/public/src/api/makeApiRequest.ts index 576f4054..e1b9b8ec 100644 --- a/public/src/api/makeApiRequest.ts +++ b/public/src/api/makeApiRequest.ts @@ -18,7 +18,15 @@ export function makeApiRequest( if (error.response.status === 401) { sessionStorage.removeItem('email'); sessionStorage.removeItem('token'); - window.location.reload(); + return { + ...error, + errorText: + 'Authentication failed, please check your credentials and try again' + }; } + return { + ...error, + errorText: 'Something went wrong. Please try again later' + }; }); } diff --git a/public/src/interfaces/User.ts b/public/src/interfaces/User.ts index e621a6cd..9598f008 100644 --- a/public/src/interfaces/User.ts +++ b/public/src/interfaces/User.ts @@ -17,6 +17,7 @@ export enum LoginFormMode { export interface LoginResponse { email: string; ldapProfileLink: string; + errorText: string | null; } export interface RegistrationUser { diff --git a/public/src/pages/auth/Login/Login.tsx b/public/src/pages/auth/Login/Login.tsx index 321f3bb5..301806b9 100644 --- a/public/src/pages/auth/Login/Login.tsx +++ b/public/src/pages/auth/Login/Login.tsx @@ -43,6 +43,7 @@ export const Login: FC = () => { const [loginResponse, setLoginResponse] = useState(); const [ldapResponse, setLdapResponse] = useState>([]); + const [errorText, setErrorText] = useState(); const [mode, setMode] = useState(LoginFormMode.BASIC); const [csrf, setCsrf] = useState(); @@ -74,9 +75,12 @@ export const Login: FC = () => { getUser(params, config) .then((data: LoginResponse) => { setLoginResponse(data); - return data.email; + return data; }) - .then((email) => sessionStorage.setItem('email', email)); + .then(({ email, errorText }) => { + setErrorText(errorText); + sessionStorage.setItem('email', email); + }); }; const sendLdap = () => { @@ -181,7 +185,7 @@ export const Login: FC = () => { onInput={onInput} /> - + {errorText &&
{errorText}
}