保存第一次login历史logging后,ExpressJS应用login失败
我使用PassportJS,MongoDB(Mongoose)和JSON Web令牌实现了一个ExpressJS应用程序。
在成功login路线实施
await user.insertLoginTime(); const token = user.generateJwt(); res.status(200).json({ token });
Mongoose模型方法'insertLoginTime'
userSchema.methods.insertLoginTime = async function() { try { const presentTime = new Date().getTime(); await this.loginHistory.push(presentTime); await this.save(); return; } catch (error) { throw new Error(error); } };
首先login成功,“邮递员”收到令牌,但在接下来的尝试中返回无效的密码错误。
删除'insertLoginTime'方法成功login多次尝试。 在“insertLoginTime”实现中是否有任何错误?
我已经解决了这个问题。 这是因为我添加了密码散列到架构的'预'挂钩'保存'。 在保存login历史logging时,哈希密码被再次哈希并保存。 这是删除实际密码散列,并导致下一次尝试失败。
- 如何从mongodb获取数据,并使用nodejs显示为d3图表
- Socket 1.0重复连接多次
- 使用application / x-www-form-urlencoded使用node.js发送数据
- 在Azure移动应用程序的Azure表脚本中插入不同的表
- Node.js(express,mongodb)注册过程
- unit testing用passport.js和express.jslogin
- Node.js – Express.js JWT在浏览器响应中总是返回一个无效的令牌错误
- openshift nodeJS应用程序 – git最新/服务器运行没有错误,但我仍然看到欢迎页面
- 如何通过Angular,Express和Mongoose执行请求放置?