Mongodb 我的passport身份验证功能未运行

Mongodb 我的passport身份验证功能未运行,mongodb,express,mongoose,passport.js,Mongodb,Express,Mongoose,Passport.js,我有一个函数(请参阅代码),除了user.comparehashandpass()函数外,其他一切都正常工作 这是一个nodejs express mongoose应用程序。前一阵子还不错,但我不知道出了什么问题 除了user.compareHashAndPass()之外,该代码可以正常工作 我已将model.method包含在模型文件中。正如我所说的,不久前它还可以正常工作 userSchema.methods.compareHashandpass = function(password,

我有一个函数(请参阅代码),除了user.comparehashandpass()函数外,其他一切都正常工作

这是一个nodejs express mongoose应用程序。前一阵子还不错,但我不知道出了什么问题

除了user.compareHashAndPass()之外,该代码可以正常工作

我已将model.method包含在模型文件中。正如我所说的,不久前它还可以正常工作

userSchema.methods.compareHashandpass =  function(password, hash, cb){
            bcrypt.compare(password, hash, function(err, res) {
            if (err) return cb(err);
            if (res === false) {
            return false
            } else {
            return true
            }
            });
        };

如果数据库中的密码和用户提供的密码未签出,则应返回消息:“密码不正确”。它只是验证用户名。即使密码错误,它也会返回“user”。

在函数中,您会返回true/false,而不是回调(
cb
)请尝试:


在函数中,返回true/false而不是回调(
cb
),请尝试:

userSchema.methods.compareHashandpass =  function(password, hash, cb){
            bcrypt.compare(password, hash, function(err, res) {
            if (err) return cb(err);
            if (res === false) {
            return false
            } else {
            return true
            }
            });
        };
userSchema.methods.compareHashandpass =  function(password, hash, cb){
            bcrypt.compare(password, hash, function(err, res) {
            if (err) return cb(err);
            if (res === false) {
              cb(null,false);
            } else {
              cb(nuul, true);
            }
            });
        };