fix: stop redundant fetching /auth/login

This commit is contained in:
dec0dOS 2022-06-18 14:30:48 +03:00
parent 4151978a68
commit ce9f7943c0

View file

@ -1,13 +1,18 @@
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();
useEffect(() => {
async function fetchData() {
axios.get("/auth/login").then(function (response) {
if (!response.data.enabled) {
setLoggedIn(true);
@ -18,6 +23,10 @@ function HomeLoggedOut() {
setDisableAuth(false);
}
});
}
fetchData();
}, [history, setDisableAuth, setLoggedIn, setToken]);
return (
<Grid
container