aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/passport.js8
1 files changed, 8 insertions, 0 deletions
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());