我正在使用react-native,node(10.4.0),passport(0.4.0)和bcryptjs(2.4.3)构建api登录

登录运行时,它返回404错误 .

module.exports = function (passport) {
passport.use(new LocalStrategy({usernameField: 'email' }, (email, password, done) => {
    User.findOne({
        email:email,
    }).then(user => {
        console.log(user)
        if (!user) {
            return done(null, false);
        }

        bcrypt.compare(password, user.password, (err, isMatch) => {
            if (err) throw err;
            console.log(err)
            if (isMatch) {
                console.log(isMatch)
                console.log(password)
                console.log(user.password)
                return done(null, user)
            } else {
                return done(null, false)
            }
        })
    })
}));

passport.serializeUser(function(user, done) {
    done(null, user.id);
});

passport.deserializeUser(function(id, done) {
    User.findById(id, function(err, user) {
        done(err, user);
    });
});

}

正如您所看到的,我在护照身份验证中有几个console.logs .

第一个console.log(用户)返回正确的用户 . 我有多个正在使用的测试用户 .

console.log(err)返回null

console.log(isMatch) - callback返回true

console.log(password)返回计划文本密码1234

console.log(user.password)返回1234的哈希值和盐

$2a$10$RreQxxB.CKgyx3to4KgrgeWmQChJgaAjfPVxMeQmfUZf2Ol1wgJU2

console.log(密码)是否应该返回bcrypt.compare的输入密码的哈希和salt版本?

此外,404很奇怪,因为回调布尔值匹配true .

谢谢你看看我真的很感激 .