mirror of
https://github.com/Foltik/Shimapan
synced 2025-01-07 08:42:49 -05:00
Change requireAuth to only export itself
This commit is contained in:
parent
f97070452b
commit
094a45b6be
@ -9,7 +9,7 @@ const Invite = require(ModelPath + 'Invite.js');
|
|||||||
const passport = require('passport');
|
const passport = require('passport');
|
||||||
|
|
||||||
const canonicalizeRequest = require('../util/canonicalize').canonicalizeRequest;
|
const canonicalizeRequest = require('../util/canonicalize').canonicalizeRequest;
|
||||||
const requireAuth = require('../util/requireAuth').requireAuth;
|
const requireAuth = require('../util/requireAuth');
|
||||||
const wrap = require('../util/wrap.js');
|
const wrap = require('../util/wrap.js');
|
||||||
|
|
||||||
// Wraps passport.authenticate to return a promise
|
// Wraps passport.authenticate to return a promise
|
||||||
|
@ -11,7 +11,7 @@ const multer = require('multer');
|
|||||||
const fileUpload = multer({dest: config.get('Upload.path')}).single('file');
|
const fileUpload = multer({dest: config.get('Upload.path')}).single('file');
|
||||||
const fsPromises = require('fs').promises;
|
const fsPromises = require('fs').promises;
|
||||||
|
|
||||||
const requireAuth = require('../util/requireAuth').requireAuth;
|
const requireAuth = require('../util/requireAuth');
|
||||||
const wrap = require('../util/wrap.js');
|
const wrap = require('../util/wrap.js');
|
||||||
|
|
||||||
const generatedIdExists = async id =>
|
const generatedIdExists = async id =>
|
||||||
|
@ -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 and has the desired scope, continue.
|
||||||
// If the request is authenticated, but lacks the required scope, return 403 Forbidden.
|
// If the request is authenticated, but lacks the required scope, return 403 Forbidden.
|
||||||
// If the request is unauthenticated, return 401 Unauthorized.
|
// If the request is unauthenticated, return 401 Unauthorized.
|
||||||
exports.requireAuth = scope =>
|
const requireAuth = scope =>
|
||||||
wrap(async (req, res, next) => {
|
wrap(async (req, res, next) => {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
if (scope ? verifyScope(req.session.passport.scope, scope) : true) {
|
if (scope ? verifyScope(req.session.passport.scope, scope) : true) {
|
||||||
@ -34,4 +34,6 @@ exports.requireAuth = scope =>
|
|||||||
} else {
|
} else {
|
||||||
res.status(401).json({'message': 'Unauthorized.'});
|
res.status(401).json({'message': 'Unauthorized.'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports = requireAuth;
|
Loading…
Reference in New Issue
Block a user