对象:null 原型不允许检索值

Object: null prototype does not allow to retrieve a value

我在尝试比较密码时遇到此错误

UnhandledPromiseRejectionWarning: Error: data and hash arguments required

事情是 user.password returns 未定义,但是当我 console.log(用户)它 returns 模型

像这样

ModelBase {
  attributes:
   [Object: null prototype] {
     username: 'billy',
     id: 4,
     password:
      'b$oIIn*******AnNkr/Pt89S****W3Vi2o8DYBgnEy9t9gcje',
     email: 'exampleman@example.com',
     created_at: 2019-05-28T20:00:37.164Z,
     updated_at: 2019-05-28T20:00:37.164Z },

所以我不明白为什么我在做 user.password

时得到 undefined

passport.js

 .......
    passport.use('login', 
        new Local(
        {
            usernameField:'username',
            passwordField:'password',
            session:false
        },
        (username, password, done, req) => {
            try{
                User.forge({username: username}).fetch()
                .then(user => {
                    if(user === null){
                        return done(null, false, {message: 'Username doesn\'t exist'})
                    }
                    else{

                        console.log(user);  // logs out user model along with password info 

                       // not getting user.password from user model.
                      bcrypt.compare(password, user.password)
                        .then(response => {
                            if(response !== true){
                                console.log('passwords do not match');
                                return done(null, false, {message:'passwords do not match'} )
                            }
                            console.log('user found & authenticated');
                            return done(null, user); 
                        })                
                    }
                })
            }catch(err){
                done(err);
            }
        }
    ))

尝试与 user.attributes.password 进行比较。