diff --git a/app/routes/auth.js b/app/routes/auth.js index 349f7fd..df94970 100644 --- a/app/routes/auth.js +++ b/app/routes/auth.js @@ -9,7 +9,7 @@ const Invite = require(ModelPath + 'Invite.js'); const passport = require('passport'); const canonicalizeRequest = require('../util/canonicalize').canonicalizeRequest; -const requireAuth = require('../util/requireAuth').requireAuth; +const requireAuth = require('../util/requireAuth'); const wrap = require('../util/wrap.js'); // Wraps passport.authenticate to return a promise diff --git a/app/routes/upload.js b/app/routes/upload.js index 0278d0c..1da2e23 100644 --- a/app/routes/upload.js +++ b/app/routes/upload.js @@ -11,7 +11,7 @@ const multer = require('multer'); const fileUpload = multer({dest: config.get('Upload.path')}).single('file'); const fsPromises = require('fs').promises; -const requireAuth = require('../util/requireAuth').requireAuth; +const requireAuth = require('../util/requireAuth'); const wrap = require('../util/wrap.js'); const generatedIdExists = async id => diff --git a/app/util/requireAuth.js b/app/util/requireAuth.js index a1f21b1..6cdb0d8 100644 --- a/app/util/requireAuth.js +++ b/app/util/requireAuth.js @@ -8,7 +8,7 @@ const verifyScope = (scope, requiredScope) => scope.indexOf(requiredScope) !== - // If the request is authenticated and has the desired scope, continue. // If the request is authenticated, but lacks the required scope, return 403 Forbidden. // If the request is unauthenticated, return 401 Unauthorized. -exports.requireAuth = scope => +const requireAuth = scope => wrap(async (req, res, next) => { if (req.isAuthenticated()) { if (scope ? verifyScope(req.session.passport.scope, scope) : true) { @@ -34,4 +34,6 @@ exports.requireAuth = scope => } else { res.status(401).json({'message': 'Unauthorized.'}); } - }); \ No newline at end of file + }); + +module.exports = requireAuth; \ No newline at end of file