Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created September 27, 2014 05:09
Show Gist options
  • Save dhigginbotham/b639d1c1df9a333c02a4 to your computer and use it in GitHub Desktop.
Save dhigginbotham/b639d1c1df9a333c02a4 to your computer and use it in GitHub Desktop.
var roles = {
optin: 1,
user: 3,
admin: 10
};
function canPlayRoleOf(user, role) {
if (roles.hasOwnProperty(role)) {
return (user.role >= roles[role] ? true : false);
} else {
return null;
}
}
function roleMiddleware(req, res, next) {
if (req.user) {
req.canPlayRoleOf = canPlayRoleOf;
}
next();
}
module.exports = roleMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment