From 35b614b4fc8a382ac80dab723847d394ff734a41 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 2 Nov 2023 19:52:50 +0100 Subject: [PATCH] fixed reloading login page if user is deactivated --- src/Pages/Login/index.js | 17 +++++++++++++---- src/utils.js | 9 +++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Pages/Login/index.js b/src/Pages/Login/index.js index 189b623..d50e887 100644 --- a/src/Pages/Login/index.js +++ b/src/Pages/Login/index.js @@ -4,6 +4,7 @@ import { Constants, EncodeStringToBase64, myFetch, + myFetchContentType, setUserSessionToLocalStorage, } from "../../utils"; import { useState } from "react"; @@ -39,10 +40,18 @@ export default function Login() { return; } - myFetch("/user/auth/login", "POST", { - username: username, - password: EncodeStringToBase64(password), - }) + myFetch( + "/user/auth/login", + "POST", + { + username: username, + password: EncodeStringToBase64(password), + }, + {}, + myFetchContentType.JSON, + "", + true + ) .then((data) => { setUserSessionToLocalStorage(data.Session); window.location.href = "/"; diff --git a/src/utils.js b/src/utils.js index c51547d..abd10bc 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1398,7 +1398,8 @@ export function myFetch( body = null, headers = {}, contentType = myFetchContentType.JSON, - fetchUrl = Constants.API_ADDRESS + fetchUrl = Constants.API_ADDRESS, + ignoreUnauthorized = false ) { const getContentType = () => { if (contentType === myFetchContentType.JSON) return "application/json"; @@ -1424,11 +1425,15 @@ export function myFetch( body: getBody(), }; + if (fetchUrl == "") { + fetchUrl = Constants.API_ADDRESS; + } + return fetch(`${fetchUrl}${url}`, requestOptions) .then((response) => { // if status is not in range 200-299 if (!response.ok) { - if (response.status === 401) { + if (!ignoreUnauthorized && response.status === 401) { setUserSessionToLocalStorage(""); window.location.href = "/"; }