mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-05 20:41:43 -07:00
Merge pull request #82 from 9p4/disable-auth-properly
fix: disable authentication properly
This commit is contained in:
commit
4151978a68
5 changed files with 29 additions and 16 deletions
|
@ -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>
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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"))}`,
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue