问题描述
我一直在寻找一段时间,看不到找到一个确定的文档来源。当我搜索这些,第一个Google结果是StackOverflow。
I've been looking for a while, and can't see to find a definitive documentation source. When I search for these, the first Google results are to StackOverflow.
有没有更多的中间件功能类似于这个?
Are there any more middleware functions similar to this?
推荐答案
虽然没有明确记录在任何地方容易找到,您可以看到被认证的位置
和 isUnauthenticated
标志在Passport代码中设置在。
While not explicitly documented anywhere easily found, you can see where the the isAuthenticated
and isUnauthenticated
flags are set in the Passport code at https://github.com/jaredhanson/passport/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js#L74.
ensureAuthenticated
不是官方的,但可以通过以下方式实现:
ensureAuthenticated
is not official, but can be implemented via the following:
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated())
return next();
else
// Return error content: res.jsonp(...) or redirect: res.redirect('/login')
}
app.get('/account', ensureAuthenticated, function(req, res) {
// Do something with user via req.user
});
这篇关于“确认认证”的文件" isAuthenticated"护照的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!