From 6388e2b98843ad8ee5db855632334174efdaeedc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 13 Jul 2021 11:20:23 -0700 Subject: user admin field and auth middleware --- lib/passport.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/passport.js b/lib/passport.js index 70e002b9..9b88f27c 100644 --- a/lib/passport.js +++ b/lib/passport.js @@ -43,4 +43,12 @@ optionalAuth = function(req, res, next) { })(req, res, next); }; +adminAuth = (req, res, next) => { + passport.authenticate("jwt", { session: false }, function(err, user, info) { + if (!(user && user.admin)) throw new Error("restricted"); + req.user = user; + next(); + })(req, res, next); +}; + app.use(passport.initialize()); -- cgit v1.2.3