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 { useLocalStorage } from "react-use";
|
||||
import axios from "axios";
|
||||
import { useHistory } from "react-router-dom";
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
function HomeLoggedOut() {
|
||||
const [, setLoggedIn] = useLocalStorage("loggedIn", false);
|
||||
const [, setToken] = useLocalStorage("token", null);
|
||||
const [, setDisableAuth] = useLocalStorage("disableAuth", false);
|
||||
const history = useHistory();
|
||||
axios.get("/auth/login").then(function (response) {
|
||||
if (!response.data.enabled) {
|
||||
setLoggedIn(true);
|
||||
setDisableAuth(true);
|
||||
setToken("");
|
||||
history.go(0);
|
||||
} else {
|
||||
setDisableAuth(false);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
axios.get("/auth/login").then(function (response) {
|
||||
if (!response.data.enabled) {
|
||||
setLoggedIn(true);
|
||||
setDisableAuth(true);
|
||||
setToken("");
|
||||
history.go(0);
|
||||
} else {
|
||||
setDisableAuth(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
fetchData();
|
||||
}, [history, setDisableAuth, setLoggedIn, setToken]);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
|
|
Loading…
Reference in a new issue