Skip to content

Instantly share code, notes, and snippets.

@fnakstad
Created August 6, 2013 15:43
Show Gist options
  • Save fnakstad/6165691 to your computer and use it in GitHub Desktop.
Save fnakstad/6165691 to your computer and use it in GitHub Desktop.
function ensureAuthorized(req, res, next) {
var role;
if(!req.user) role = userRoles.public;
else role = req.user.role;
var accessLevel = _.findWhere(routes, { path: req.route.path }).accessLevel || accessLevels.public;
if(!(accessLevel.bitMask & role.bitMask)) return res.send(403);
return next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment