gpt4 book ai didi

express - "ensureAuthentication" "isAuthenticated" Passport 功能的文档?

转载 作者:行者123 更新时间:2023-12-02 11:31:05 24 4
gpt4 key购买 nike

我已经寻找了一段时间,但找不到明确的文档来源。当我搜索这些内容时,第一个 Google 结果是 StackOverflow。

还有类似的中间件功能吗?

最佳答案

虽然在任何容易找到的地方都没有明确记录,但您可以在 Passport 代码 https://github.com/jaredhanson/passport/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js#L74 中看到 isAuthenticatedisUn​​authenticated 标志的设置位置。 。

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

关于express - "ensureAuthentication" "isAuthenticated" Passport 功能的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14188834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com