I have an express server and I'm trying to write some middleware that checks to see if a user is of the specified level, but am at a loss on how to pass a level value to the middleware.
example app.js:
app.get('/restricted',verify.auth('4') , routes.index);
example auth.js
exports.verify = function(req, res, next, requiredLevel) {
if(userLevel>=requiredLevel){next};
}
try this
verify.auth=function(requiredLevel){
return function(req,res,next){
// requiredLevel is visible here ..
// manipulate req,res
//..
// call next middleware
next();
}
}
also working with sessions so you don't leave the user level to be specified by user..