Passport.js为node.js和Express提供了出色的身份验证,其中包括中间件解决方案:
ensureAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
return res.redirect("/login");
};
如何在express-resource模块中使用此中间件?很遗憾,
app.resource('users', ensureAuthenticated, require('./resources/users'));
不起作用。
最佳答案
我知道这为时已晚,并且回答了原始帖子,但是,我一直在寻找相同的答案,并且找到了我认为其他人可能想知道的解决方案。
只要确保确保从护照调用了Authenticated。
app.resource('users', passport.ensureAuthenticated, require('./resources/users'));
在这里找到:https://gist.github.com/1941301
关于javascript - 使用身份验证中间件表达资源吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9213707/