fixed reloading login page if user is deactivated
parent
3d90bb1a85
commit
35b614b4fc
|
@ -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 = "/";
|
||||
|
|
|
@ -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 = "/";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue