title: Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Incorrect arguments')
body: <p>This Error appears when i want to LOG IN</p>
  
  <blockquote>
    <p>events.js:189</p>
    
    <p>throw err; // Unhandled 'error' event</p>
    
    <p>^</p>
    
    <p>Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Incorrect arguments')</p>
    
    <p>at Function.emit (events.js:187:17)</p>
    
    <p>at E:\My Drive\src code\node.js\Revision\regSys\node_modules\mongoose\lib\model.js:4830:13    </p>
    
    <p>at E:\My Drive\src code\node.js\Revision\regSys\node_modules\mongoose\lib\query.js:4390:12</p>
    
    <p>at process.nextTick (E:\My Drive\src code\node.js\Revision\regSys\node_modules\mongoose
    \lib\query.js:2869:28)    at process._tickCallback (internal/process/next_tick.js:61:11)</p>
    
    <p>[nodemon] app crashed - waiting for file changes before starting...</p>
  </blockquote>
  
  <p><strong>Schema (db.js)</strong></p>
  
  <pre><code>const mongoose = require('mongoose');
  const bcrypt = require('bcrypt-nodejs');
  
  const stDB = mongoose.Schema({
      email : {
          type: String,
          required: true
      },
      password : {
          type: String,
          required: true
      }
  });
  
  stDB.methods.hashPassword = function(password){
      return bcrypt.hashSync(password, bcrypt.genSaltSync(5));
  }
  stDB.methods.comparePasswords = (password) =&gt; {
      return bcrypt.compareSync(password, this.password)
  }
  
  
  module.exports = mongoose.model('db', stDB);
  </code></pre>
  
  <p><strong>config/passport.js</strong></p>
  
  <pre><code>passport.use('local-signin' , new localStrategy({
      usernameField : 'email' ,
      passwordField : 'password' ,
      passReqToCallback : true ,
  } , ( req , email , password ,  done)=&gt;{
  
  
      User.findOne({email : email} , (err , user)=&gt;{
          if(err){
              return done (err)
          }
  
          if (! user){
              return done( null , false , req.flash('signinError' , 'this user not found'))
          }
          if (! user.comparePasswords(password)){
              return done(null , false , req.flash('signinError' , 'wrong password'))
          }
  
          return done(null , user)
      })
  
  }))
  </code></pre>
  
  <blockquote>
    <p><strong>"bcrypt-nodejs": "0.0.3"</strong></p>
    
    <p><strong>"passport": "^0.4.0"</strong></p>
    
    <p><strong>"passport-local": "^1.0.0"</strong></p>
    
    <p><strong>"node": "10.16.1"</strong></p>
    
    <p><strong>"express": "~4.16.1"</strong></p>
  </blockquote>