feat: disable auth (#59)

This commit is contained in:
Sambhav Saggi 2022-05-23 22:09:30 -04:00
parent 30069a699f
commit e7fb4d0aa8
No known key found for this signature in database
GPG key ID: 8F731DA8AFBAE35D
3 changed files with 33 additions and 8 deletions

View file

@ -20,14 +20,18 @@ async function authorize(username, password, callback) {
exports.isAuthorized = isAuthorized;
async function isAuthorized(req, res, next) {
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" });
}
if (process.env.ZU_DISABLE_AUTH === "true") {
next();
} 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" });
}
}
}