提问人:Omar Salem 提问时间:12/2/2017 最后编辑:marc_sOmar Salem 更新时间:12/2/2017 访问量:31
为什么这个陈述不能正常工作,总是给出“真实”?
Why is this statement isn't working properly and always giving 'true'?
问:
尝试对用户进行身份验证时,此函数始终返回 true:
exports.IsUser = function(req, res, next) {
if (req.user.role === "user") {
next();
} else {
return res.status(401).json({ message: 'Unauthorized user!' });
}
};
json req.user:
{
"email": "[email protected]",
"fullName": "testname",
"role": "user",
"iat": 1502495033
}
路由功能:
app.route('/')
.get(function(req, res, next) {
res.json(req.user);})
.post(control.IsUser);
答: 暂无答案
评论
always giving true