我一直在寻找一段时间,但找不到明确的文档来源.当我搜索这些时,第一个 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?
推荐答案虽然没有在任何容易找到的地方明确记录,但您可以看到 isAuthenticated 和 isUnauthenticated 标志的位置在 github/jaredhanson/的 Passport 代码中设置护照/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js#L74.
While not explicitly documented anywhere easily found, you can see where the the isAuthenticated and isUnauthenticated flags are set in the Passport code at github/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 });更多推荐
“ensureAuthentication"文档“已认证"护照的作用?
发布评论