Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个快速服务器,我正在尝试编写一些中间件来检查用户是否处于指定级别,但是不知道如何将level值传递给中间件。
level
示例 app.js:
app.get('/restricted',verify.auth('4') , routes.index);
示例 auth.js
exports.verify = function(req, res, next, requiredLevel) { if(userLevel>=requiredLevel){next}; }
尝试这个
verify.auth=function(requiredLevel){ return function(req,res,next){ // requiredLevel is visible here .. // manipulate req,res //.. // call next middleware next(); } }
还使用会话,因此您不会将用户级别留给用户指定..