From b341199c6985d255b2f078e876c77b5d214ec0d5 Mon Sep 17 00:00:00 2001 From: clement callaert Date: Sat, 4 Nov 2023 01:32:44 +0100 Subject: [PATCH] video --- middlewares/auth-middleware.js | 15 ++++++++++----- views/401.ejs | 2 +- views/403.ejs | 2 +- views/404.ejs | 2 +- views/500.ejs | 2 +- views/connexion.ejs | 2 +- views/creer_compte.ejs | 2 +- views/futur.ejs | 2 +- views/hotLine.ejs | 2 +- views/index.ejs | 2 +- views/profile.ejs | 2 +- 11 files changed, 20 insertions(+), 15 deletions(-) diff --git a/middlewares/auth-middleware.js b/middlewares/auth-middleware.js index c6af7c8..deda8e9 100644 --- a/middlewares/auth-middleware.js +++ b/middlewares/auth-middleware.js @@ -9,13 +9,18 @@ async function auth (req, res, next) { if (!user || !isAuth) { return next(); } - const userDoc = await db.getDb().collection('users').findOne({_id: user.id}) - const isAdmin = userDoc.isAdmin; - res.locals.user = userDoc; - res.locals.isAuth = isAuth; - res.locals.isAdmin = isAdmin; + if (userDoc && userDoc.isAdmin) { + + const isAdmin = userDoc.isAdmin; + + res.locals.user = userDoc; + res.locals.isAuth = isAuth; + res.locals.isAdmin = isAdmin; + } + + next(); } diff --git a/views/401.ejs b/views/401.ejs index 4077ad7..1230784 100644 --- a/views/401.ejs +++ b/views/401.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>

diff --git a/views/403.ejs b/views/403.ejs index 90a4dc9..966429b 100644 --- a/views/403.ejs +++ b/views/403.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>

diff --git a/views/404.ejs b/views/404.ejs index b4f8bbf..cc81ce1 100644 --- a/views/404.ejs +++ b/views/404.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>

diff --git a/views/500.ejs b/views/500.ejs index 048a229..b810616 100644 --- a/views/500.ejs +++ b/views/500.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>

diff --git a/views/connexion.ejs b/views/connexion.ejs index 5d47111..43f596b 100644 --- a/views/connexion.ejs +++ b/views/connexion.ejs @@ -5,7 +5,7 @@ <%- include('includes/header') %>

diff --git a/views/creer_compte.ejs b/views/creer_compte.ejs index 7623369..0ef6006 100644 --- a/views/creer_compte.ejs +++ b/views/creer_compte.ejs @@ -5,7 +5,7 @@ <%- include('includes/header') %>

diff --git a/views/futur.ejs b/views/futur.ejs index a0e17d1..160648b 100644 --- a/views/futur.ejs +++ b/views/futur.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>

diff --git a/views/hotLine.ejs b/views/hotLine.ejs index a5f9a2b..33e4ae0 100644 --- a/views/hotLine.ejs +++ b/views/hotLine.ejs @@ -6,7 +6,7 @@ <%- include('includes/header') %>

diff --git a/views/index.ejs b/views/index.ejs index 0c254a1..cb635f6 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -5,7 +5,7 @@ <%- include('includes/header.ejs') %>
diff --git a/views/profile.ejs b/views/profile.ejs index 1b0f313..22cd117 100644 --- a/views/profile.ejs +++ b/views/profile.ejs @@ -5,7 +5,7 @@ <%- include('includes/header') %>