diff --git a/frontend/src/components/Bar/Bar.jsx b/frontend/src/components/Bar/Bar.jsx index aac68c6..fe075cd 100644 --- a/frontend/src/components/Bar/Bar.jsx +++ b/frontend/src/components/Bar/Bar.jsx @@ -47,11 +47,15 @@ function Bar() { // name: "Settings", // to: "/settings", // }, - !disabledAuth && { - name: "Log out", - divide: true, - onClick: onLogOutClick, - }, + ...(!disabledAuth + ? [ + { + name: "Log out", + divide: true, + onClick: onLogOutClick, + }, + ] + : []), ]; return ( @@ -74,69 +78,68 @@ function Bar() { {/* The filter removes all elements that are "true" or "false" */} - {loggedIn && - menuItems.filter((e) => typeof e !== "boolean").length > 0 && ( - <> - + {loggedIn && menuItems.length > 0 && ( + <> + - - {menuItems.map((menuItem, index) => { - if ( - menuItem.hasOwnProperty("condition") && - !menuItem.condition - ) { - return null; - } + + {menuItems.map((menuItem, index) => { + if ( + menuItem.hasOwnProperty("condition") && + !menuItem.condition + ) { + return null; + } - let component = null; + let component = null; - if (menuItem.to) { - component = ( - - {menuItem.name} - - ); - } else { - component = ( - { - closeMenu(); + if (menuItem.to) { + component = ( + + {menuItem.name} + + ); + } else { + component = ( + { + closeMenu(); - menuItem.onClick(); - }} - > - {menuItem.name} - - ); - } + menuItem.onClick(); + }} + > + {menuItem.name} + + ); + } - if (menuItem.divide) { - return ( - - + if (menuItem.divide) { + return ( + + - {component} - - ); - } + {component} + + ); + } - return component; - })} - - - )} + return component; + })} + + + )} {!loggedIn && LogIn()} diff --git a/frontend/src/components/HomeLoggedIn/HomeLoggedIn.jsx b/frontend/src/components/HomeLoggedIn/HomeLoggedIn.jsx index ff45f76..2dbc1bd 100644 --- a/frontend/src/components/HomeLoggedIn/HomeLoggedIn.jsx +++ b/frontend/src/components/HomeLoggedIn/HomeLoggedIn.jsx @@ -1,5 +1,7 @@ import { useState, useEffect } from "react"; import { useHistory } from "react-router-dom"; +import { useLocalStorage } from "react-use"; +import axios from "axios"; import { Divider, Button, Grid, Typography, Box } from "@material-ui/core"; import useStyles from "./HomeLoggedIn.styles"; @@ -11,10 +13,22 @@ import { generateNetworkConfig } from "utils/NetworkConfig"; function HomeLoggedIn() { const [networks, setNetworks] = useState([]); + const [, setLoggedIn] = useLocalStorage("loggedIn", false); + const [, setDisableAuth] = useLocalStorage("disableAuth", false); + const [token, setToken] = useLocalStorage("token", null); const classes = useStyles(); const history = useHistory(); + axios.get("/auth/login").then(function (response) { + if (response.data.enabled) { + setDisableAuth(false); + if (!token || token.length === 0) { + setLoggedIn(false); + } + } + }); + const createNetwork = async () => { const network = await API.post("network", generateNetworkConfig()); console.log(network);