fixed reloading login page if user is deactivated

main
alex 2023-11-02 19:52:50 +01:00
parent 3d90bb1a85
commit 35b614b4fc
2 changed files with 20 additions and 6 deletions

View File

@ -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", {
myFetch(
"/user/auth/login",
"POST",
{
username: username,
password: EncodeStringToBase64(password),
})
},
{},
myFetchContentType.JSON,
"",
true
)
.then((data) => {
setUserSessionToLocalStorage(data.Session);
window.location.href = "/";

View File

@ -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 = "/";
}