mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2024-09-20 06:56:05 +08:00
fix: stop redundant fetching /auth/login
This commit is contained in:
parent
4151978a68
commit
ce9f7943c0
|
@ -1,23 +1,32 @@
|
||||||
|
import { useEffect } from "react";
|
||||||
import { Grid, Typography } from "@material-ui/core";
|
import { Grid, Typography } from "@material-ui/core";
|
||||||
import { useLocalStorage } from "react-use";
|
import { useLocalStorage } from "react-use";
|
||||||
import axios from "axios";
|
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
function HomeLoggedOut() {
|
function HomeLoggedOut() {
|
||||||
const [, setLoggedIn] = useLocalStorage("loggedIn", false);
|
const [, setLoggedIn] = useLocalStorage("loggedIn", false);
|
||||||
const [, setToken] = useLocalStorage("token", null);
|
const [, setToken] = useLocalStorage("token", null);
|
||||||
const [, setDisableAuth] = useLocalStorage("disableAuth", false);
|
const [, setDisableAuth] = useLocalStorage("disableAuth", false);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
axios.get("/auth/login").then(function (response) {
|
|
||||||
if (!response.data.enabled) {
|
useEffect(() => {
|
||||||
setLoggedIn(true);
|
async function fetchData() {
|
||||||
setDisableAuth(true);
|
axios.get("/auth/login").then(function (response) {
|
||||||
setToken("");
|
if (!response.data.enabled) {
|
||||||
history.go(0);
|
setLoggedIn(true);
|
||||||
} else {
|
setDisableAuth(true);
|
||||||
setDisableAuth(false);
|
setToken("");
|
||||||
|
history.go(0);
|
||||||
|
} else {
|
||||||
|
setDisableAuth(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
fetchData();
|
||||||
|
}, [history, setDisableAuth, setLoggedIn, setToken]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
|
|
Loading…
Reference in a new issue