护照 – 本地 – mongoosechangePasswordfunction
我想要有用户可以更改密码的function。 我已经实现了这样一个路由( '/ resetPasswd' ):
UserRouter.route('/resetPasswd') .post(function (req, res, next) { passport.authenticate('local', function (err, user, info) { user.changePassword(req.body.oldPassword, req.body.newPassword, function (err, user) { if (err) next(err); res.json('password changes successfully !'); }) })(req, res, next); });
这是我发送的身体:
{ "oldpassword": "secret", "newPassword": "new" }
但是我得到这个错误作为回应:
{ "message": "user.changePassword is not a function", "error": {} }
这是我的模式的图片:
用户架构:
我不认为我应该在我的模式中声明changePassword函数(因为它是由护照本地mongoose提供的 ,虽然我添加了它,但仍然得到相同的错误)我在这里犯了什么错误?
实际上昨晚有人有同样的问题。 他们的问题是需要更新的软件包。 我会检查你是最新的版本。