From 5e345852a79e7f803d7796cb14c0c13a5be3ad14 Mon Sep 17 00:00:00 2001 From: LarsVomMars Date: Tue, 20 Oct 2020 09:27:37 +0200 Subject: Debugging --- auth/index.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'auth') diff --git a/auth/index.js b/auth/index.js index 2e3fa17..3109586 100644 --- a/auth/index.js +++ b/auth/index.js @@ -10,8 +10,9 @@ function checkUser(req, res, next) { } function checkAdmin(req, res, next) { - if (!(req.session.loggedIn && req.session.isAdmin)) return res.redirect("/" + (req.session.isAdmin ? "auth" : "")); - else next(); + if (req.session.loggedIn && req.session.isAdmin) next(); + else if (req.session.loggedIn) return res.redirect("/"); + else return res.redirect("/auth"); } app.use( @@ -89,13 +90,7 @@ app.get("/api/list", checkUser, async (req, res) => { }); app.get("/api/status", (req, res) => { - if (req.session.loggedIn) { - db.query("SELECT is_admin FROM users WHERE id = ?", [req.session.uid]).then((ret) => { - res.json({ loggedIn: req.session.loggedIn, admin: ret[0].is_admin ? true : false }); - }); - } else { - res.json({ loggedIn: false, admin: false }); - } + res.json({ loggedIn: req.session.loggedIn, admin: req.session.isAdmin }); }); module.exports = { auth: app, checkUser, checkAdmin }; -- cgit v1.2.3