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

@ -153,7 +153,7 @@ Advanced manual setups are also supported. Check the following environment varia
| ZU_DEFAULT_USERNAME | unset (`docker-compose.yml`: admin) | Default username that will be set on the first run |
| ZU_DEFAULT_PASSWORD | unset (`docker-compose.yml`: zero-ui) | Default password that will be set on the first run |
| ZU_DATAPATH | `data/db.json` | ZeroUI data storage path |
| ZU_DISABLE_AUTH | unset | If set to true, automatically log in all users. This is useful if ZeroUI is protected by an authentication proxy |
| ZU_DISABLE_AUTH | unset | If set to true, automatically log in all users. This is useful if ZeroUI is protected by an authentication proxy. Note that when this value is changed, the localStorage of instances of logged-in panels should be cleared |
ZeroUI could be deployed as a regular nodejs web application, but it requires ZeroTier controller that is installed with `zerotier-one` package. More info about the network controller you could read [here](https://github.com/zerotier/ZeroTierOne/tree/master/controller/#readme).

View file

@ -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" &&

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