2017-09-04 23 views
0

我想拥有用户可以更改密码的功能。 我已经实现了一个路线('/ resetPasswd')是这样的:passport-local-mongoose changePassword功能

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": {} 
} 

,这是我的架构的照片:

用户模式:

user schema

我不认为我应该在我的架构声明changePassword功能(因为它是由护照本地猫鼬提供的,虽然我加入,但仍得到同样的错误)我在这里犯了什么错误?

+0

如果您有任何问题,您可以向我们展示您的架构和中间件吗? – turmuka

+0

回复此链接http://sahatyalkabov.com/how-to-implement-password-reset-in-nodejs/它将会对你有所帮助... –

+0

@turmuka:我已经提供了我的架构图片我的文章 –

回答

1

昨晚有人遇到了同样的问题。他们的问题是需要更新的软件包。我会检查你是否在最新版本。