“ensureAuthentication”“isAuthenticated”护照的function文件?

我一直在寻找一段时间,看不到一个明确的文件来源。 当我search这些,谷歌的第一个结果是StackOverflow。

还有更多的中间件function类似吗?

虽然没有明确logging任何地方很容易find,你可以看到在https://github.com/jaredhanson/passport/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js的Passport代码中设置;isAuthenticatedisUnauthenticated标志#L74 。

ensureAuthenticated不是官方的,但可以通过以下方式实现:

 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 });