passport isAuthorized middleware. Fixed headers already sent errors.
This commit is contained in:
@@ -138,3 +138,9 @@ exports.isAuthenticated = function(req, res, next) {
|
||||
if (req.isAuthenticated()) return next();
|
||||
res.redirect('/login');
|
||||
};
|
||||
|
||||
exports.isAuthorized = function(req, res, next) {
|
||||
var provider = req.path.split('/').slice(-1)[0];
|
||||
if (_.findWhere(req.user.tokens, { kind: provider })) next();
|
||||
else res.redirect('/auth/' + provider);
|
||||
};
|
Reference in New Issue
Block a user