title: Missing password error in passport-local-mongoose
body: <p>I'm learning a node js course from coursera, while learning user authentication with passport, I'm facing this error. I have followed exactly what was said in the course, but I'm getting this error!</p>
  <p>I understand that some of the content of that course is deprecated, but how to solve this error?</p>
  <p><strong>THE ERROR</strong></p>
  <pre><code>Connected correctly to server
  (node:7856) UnhandledPromiseRejectionWarning: MissingPasswordError: No password was given
      at B:\Node\Node JS\conFusionServer\node_modules\passport-local-mongoose\index.js:103:17
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
  (node:7856) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)        
  (node:7856) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
  </code></pre>
  <p>My model</p>
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var passportLocalMongoose = require('passport-local-mongoose');
  
  var User = new Schema({
      // username: { // auto added by passport
      //     type: String,
      //     required: true,
      //     unique: true,
      // },
      // password: {
      //     type: String,
      //     required: true,
      // },
      admin: {
          type: Boolean,
          default: false,
      }
  });
  
  User.plugin(passportLocalMongoose);
  
  module.exports = mongoose.model('User', User);
  </code></pre>
  <p>My Authentication</p>
  <pre><code>var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  var User = require('./models/user');
  
  exports.local = passport.use(new LocalStrategy(User.authenticate()));
  passport.serializeUser(User.serializeUser());
  passport.deserializeUser(User.deserializeUser());
  </code></pre>
  <p>My Route</p>
  <pre><code>router.post('/signup', (req, res, next) =&gt; {
    // User.findOne({ username: req.body.username })
    User.register(new User({ username: req.body.username }, req.body.password, (err, user) =&gt; {
      if (err) {
        console.log(err);
        res.statusCode = 500;
        res.setHeader('Content-Type', 'application/json');
        res.json({ err: err });
      } else {
        console.log(user);
        passport.authenticate('local')(req, res, () =&gt; {
          res.statusCode = 200;
          res.setHeader('Content-Type', 'application/json');
          res.json({ success: true, status: 'Registration Successful' });
        });
      }
    })); // passport-local-mongoose
  });
  </code></pre>
  <p>My app.js</p>
  <pre><code>app.use(passport.initialize());
  app.use(passport.session());
  
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  
  function auth(req, res, next) {
    if (!req.user) { // auto loaded by passport
      var err = new Error('You are not authenticated!!!');
      err.status = 401;
      return next(err);
    } else {
      next();
    }
  }
  
  app.use(auth);
  </code></pre>
  <p>My Postman
  <a href="https://i.stack.imgur.com/hp5Tc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hp5Tc.png" alt="enter image description here" /></a></p>