diff --git a/backend/app.js b/backend/app.js index b2a9eff..7f46dd3 100644 --- a/backend/app.js +++ b/backend/app.js @@ -18,11 +18,13 @@ const app = express(); app.use(logger("dev")); app.use(express.json()); app.use(express.urlencoded({ extended: false })); -app.use( - bearerToken({ - headerKey: "Bearer", - }) -); +if (process.env.ZU_DISABLE_AUTH === "true") { + app.use( + bearerToken({ + headerKey: "Bearer", + }) + ); +} if ( process.env.NODE_ENV === "production" && diff --git a/frontend/src/components/Bar/Bar.jsx b/frontend/src/components/Bar/Bar.jsx index 444a06f..aac68c6 100644 --- a/frontend/src/components/Bar/Bar.jsx +++ b/frontend/src/components/Bar/Bar.jsx @@ -21,6 +21,7 @@ import LogIn from "components/LogIn"; function Bar() { const [loggedIn, setLoggedIn] = useLocalStorage("loggedIn", false); + const [disabledAuth] = useLocalStorage("disableAuth", false); const [anchorEl, setAnchorEl] = useState(null); const history = useHistory(); @@ -46,7 +47,7 @@ function Bar() { // name: "Settings", // to: "/settings", // }, - { + !disabledAuth && { name: "Log out", divide: true, onClick: onLogOutClick, @@ -72,69 +73,70 @@ function Bar() { + {/* The filter removes all elements that are "true" or "false" */} + {loggedIn && + menuItems.filter((e) => typeof e !== "boolean").length > 0 && ( + <> + - {loggedIn && ( - <> - +
+ > + )} {!loggedIn && LogIn()} diff --git a/frontend/src/components/HomeLoggedOut/HomeLoggedOut.jsx b/frontend/src/components/HomeLoggedOut/HomeLoggedOut.jsx index 2a57165..82f5550 100644 --- a/frontend/src/components/HomeLoggedOut/HomeLoggedOut.jsx +++ b/frontend/src/components/HomeLoggedOut/HomeLoggedOut.jsx @@ -6,10 +6,12 @@ import { useHistory } from "react-router-dom"; 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); } diff --git a/frontend/src/utils/API.js b/frontend/src/utils/API.js index 1d3a28b..4656032 100644 --- a/frontend/src/utils/API.js +++ b/frontend/src/utils/API.js @@ -5,7 +5,10 @@ const baseURL = "/api/"; export default axios.create({ baseURL: baseURL, responseType: "json", - headers: { - Authorization: `Bearer ${JSON.parse(localStorage.getItem("token"))}`, - }, + headers: + localStorage.getItem("disableAuth") === "true" + ? {} + : { + Authorization: `Bearer ${JSON.parse(localStorage.getItem("token"))}`, + }, });