我的控制器就像这样
//Get the Helpers
var authHelper = require('authHelper');
//Route
router.get('/manager', authHelper.checkPerm(req, res, next), function(req, res) {
});
我的authHelper.js
exports.checkPerm = function(req, res, next){
if (req.user) {
next();
} else {
res.redirect('/sign-in');
}
}
这是我得到的错误
router.get('/ manager',authHelper.checkPerm(req,res,next), 功能(req,res ^ ReferenceError:未定义req
答案 0 :(得分:1)
传递给路由参数时,您正在执行方法checkPerm
。删除括号以及参数(req, res, next)
应该是这样的:
router.get('/manager', authHelper.checkPerm, function(req, res) ...