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, Constants,
EncodeStringToBase64, EncodeStringToBase64,
myFetch, myFetch,
myFetchContentType,
setUserSessionToLocalStorage, setUserSessionToLocalStorage,
} from "../../utils"; } from "../../utils";
import { useState } from "react"; import { useState } from "react";
@ -39,10 +40,18 @@ export default function Login() {
return; return;
} }
myFetch("/user/auth/login", "POST", { myFetch(
"/user/auth/login",
"POST",
{
username: username, username: username,
password: EncodeStringToBase64(password), password: EncodeStringToBase64(password),
}) },
{},
myFetchContentType.JSON,
"",
true
)
.then((data) => { .then((data) => {
setUserSessionToLocalStorage(data.Session); setUserSessionToLocalStorage(data.Session);
window.location.href = "/"; window.location.href = "/";

View File

@ -1398,7 +1398,8 @@ export function myFetch(
body = null, body = null,
headers = {}, headers = {},
contentType = myFetchContentType.JSON, contentType = myFetchContentType.JSON,
fetchUrl = Constants.API_ADDRESS fetchUrl = Constants.API_ADDRESS,
ignoreUnauthorized = false
) { ) {
const getContentType = () => { const getContentType = () => {
if (contentType === myFetchContentType.JSON) return "application/json"; if (contentType === myFetchContentType.JSON) return "application/json";
@ -1424,11 +1425,15 @@ export function myFetch(
body: getBody(), body: getBody(),
}; };
if (fetchUrl == "") {
fetchUrl = Constants.API_ADDRESS;
}
return fetch(`${fetchUrl}${url}`, requestOptions) return fetch(`${fetchUrl}${url}`, requestOptions)
.then((response) => { .then((response) => {
// if status is not in range 200-299 // if status is not in range 200-299
if (!response.ok) { if (!response.ok) {
if (response.status === 401) { if (!ignoreUnauthorized && response.status === 401) {
setUserSessionToLocalStorage(""); setUserSessionToLocalStorage("");
window.location.href = "/"; window.location.href = "/";
} }