diff options
author | LarsVomMars | 2020-10-20 09:27:37 +0200 |
---|---|---|
committer | LarsVomMars | 2020-10-20 09:27:37 +0200 |
commit | 5e345852a79e7f803d7796cb14c0c13a5be3ad14 (patch) | |
tree | d1ec8aa70b4c2fe1acd8b4f932843d39310d5f1f /auth | |
parent | 4194f192b4e175c4abd37d093850a77efd09c8bc (diff) |
Debugging
Diffstat (limited to 'auth')
-rw-r--r-- | auth/index.js | 13 |
1 files changed, 4 insertions, 9 deletions
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 }; |