From c7e355e81f0dc36ee0673e552b5604af4e9bfdd4 Mon Sep 17 00:00:00 2001 From: clement callaert Date: Sat, 4 Nov 2023 23:08:12 +0100 Subject: [PATCH] mongodb --- middlewares/auth-middleware.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/middlewares/auth-middleware.js b/middlewares/auth-middleware.js index 44a442b..cf1cc5c 100644 --- a/middlewares/auth-middleware.js +++ b/middlewares/auth-middleware.js @@ -6,16 +6,19 @@ async function auth (req, res, next) { const user = req.session.user; const isAuth = req.session.isAuthenticated; + if (!user || !isAuth) { + return next(); + } + const userDoc = await db.getDb().collection('users').findOne({_id: user.id}) - if (userDoc && userDoc.isAdmin) { - const isAdmin = userDoc.isAdmin; + const isAdmin = userDoc.isAdmin; + + res.locals.user = userDoc; + res.locals.isAuth = isAuth; + res.locals.isAdmin = isAdmin; - res.locals.user = userDoc; - res.locals.isAuth = isAuth; - res.locals.isAdmin = isAdmin; - }