mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-06 04:51:44 -07:00
feat: disable auth (#59)
This commit is contained in:
parent
30069a699f
commit
e7fb4d0aa8
3 changed files with 33 additions and 8 deletions
|
@ -3,6 +3,14 @@ const router = express.Router();
|
||||||
|
|
||||||
const auth = require("../services/auth");
|
const auth = require("../services/auth");
|
||||||
|
|
||||||
|
router.get("/login", async function (req, res) {
|
||||||
|
if (process.env.ZU_DISABLE_AUTH === "true") {
|
||||||
|
res.send({ enabled: false });
|
||||||
|
} else {
|
||||||
|
res.send({ enabled: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.post("/login", async function (req, res) {
|
router.post("/login", async function (req, res) {
|
||||||
if (req.body.username && req.body.password) {
|
if (req.body.username && req.body.password) {
|
||||||
auth.authorize(req.body.username, req.body.password, function (err, user) {
|
auth.authorize(req.body.username, req.body.password, function (err, user) {
|
||||||
|
|
|
@ -20,14 +20,18 @@ async function authorize(username, password, callback) {
|
||||||
|
|
||||||
exports.isAuthorized = isAuthorized;
|
exports.isAuthorized = isAuthorized;
|
||||||
async function isAuthorized(req, res, next) {
|
async function isAuthorized(req, res, next) {
|
||||||
if (req.token) {
|
if (process.env.ZU_DISABLE_AUTH === "true") {
|
||||||
const user = await db.get("users").find({ token: req.token }).value();
|
next();
|
||||||
if (user) {
|
|
||||||
next();
|
|
||||||
} else {
|
|
||||||
res.status(403).send({ error: "Invalid token" });
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send({ error: "Specify token" });
|
if (req.token) {
|
||||||
|
const user = await db.get("users").find({ token: req.token }).value();
|
||||||
|
if (user) {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
res.status(403).send({ error: "Invalid token" });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(401).send({ error: "Specify token" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
import { Grid, Typography } from "@material-ui/core";
|
import { Grid, Typography } from "@material-ui/core";
|
||||||
|
import { useLocalStorage } from "react-use";
|
||||||
|
import axios from "axios";
|
||||||
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
function HomeLoggedOut() {
|
function HomeLoggedOut() {
|
||||||
|
const [, setLoggedIn] = useLocalStorage("loggedIn", false);
|
||||||
|
const [, setToken] = useLocalStorage("token", null);
|
||||||
|
const history = useHistory();
|
||||||
|
axios.get("/auth/login").then(function (response) {
|
||||||
|
if (!response.data.enabled) {
|
||||||
|
setLoggedIn(true);
|
||||||
|
setToken("");
|
||||||
|
history.go(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue