【发布时间】:2021-03-30 03:35:57
【问题描述】:
根据Passport Documentation on Sessions
...只有用户 ID 被序列化到会话中,保留金额 存储在会话中的数据很小。当后续请求 收到,这个ID用来找用户,会恢复到 请求用户。
但是我的test SPA 基于Passport form-based authentication sample 并添加了调试消息表明req.user 在app.get 路由处理程序被触发之前已经恢复。
这是来自 HTTP POST 的输出,其中用户名和护照字段为空 -
[nodemon] starting `node app.js`
agenda-spa app listening at http://localhost:3000
handling request for: / POST
handling request for: / GET
xxx get root
xxx req.user undefined
handling request for: /style.css GET
req.user 未按预期定义
这是来自带有经过身份验证的用户名和密码的 HTTP POST 的输出
handling request for: / POST
xxx passport.use sss
xxx findByUsername sss
xxx password match
xxx serializeUser { id: 1, username: 'sss', password: 'sss' }
xxx auth success
xxx deserializeUser 1
xxx findById 1
handling request for: / GET
xxx get root
xxx req.user { id: 1, username: 'sss', password: 'sss' }
xxx deserializeUser 1
xxx findById 1
handling request for: /style.css GET
我希望它是-
...
xxx deserializeUser 1
xxx findById 1
xxx req.user { id: 1, username: 'sss', password: 'sss' }
...
为什么在req.user 恢复后调用passport.deserializeUser?
【问题讨论】:
标签: node.js express passport.js