Merge pull request #82 from 9p4/disable-auth-properly

fix: disable authentication properly
This commit is contained in:
dec0dOS 2022-06-18 14:08:04 +03:00 committed by GitHub
commit 4151978a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 16 deletions

View file

@ -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,11 +47,15 @@ function Bar() {
// name: "Settings",
// to: "/settings",
// },
{
name: "Log out",
divide: true,
onClick: onLogOutClick,
},
...(!disabledAuth
? [
{
name: "Log out",
divide: true,
onClick: onLogOutClick,
},
]
: []),
];
return (
@ -72,8 +77,7 @@ function Bar() {
</Link>
</Typography>
</Box>
{loggedIn && (
{loggedIn && menuItems.length > 0 && (
<>
<Button color="inherit" onClick={openMenu}>
<MenuIcon></MenuIcon>

View file

@ -6,12 +6,16 @@ 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);
} else {
setDisableAuth(false);
}
});
return (

View file

@ -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"))}`,
},
});