title: User login with Passport js and mongoDB
body: <p>I've seen this question asked already, sorry if it seems repetitive; but I've read through a lot of the answers and they haven't helped. I keep getting a "MISSING CREDENTIALS" error no matter what I do with the login form. I'm trying to implement a user login using email and password. </p>
  
  <p>My Route File</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const passport = require('passport');
  const LocalStrategy = require('passport-local').Strategy;
  const User = require('../models/user');
  
  passport.use(new LocalStrategy((email, password, done) =&gt; {
    User.getUserByEmail(email, (err, user) =&gt; {
      if(err) throw err;
      if(!user) {
        return done(null, false, {message: 'this account does not exist'});
      }
  
      User.comparePassword(password, user.password, (err, isMatch) =&gt; {
        if(err) throw err;
        if(isMatch) {
          return done(null, user);
        }
        else {
          return done(null, false, {message: 'oops! wrong password! try again'});
        }
      });
    });
  }));
  
  passport.serializeUser((user, done) =&gt; {
    done(null, user.id);
  });
  
  passport.deserializeUser((id, done) =&gt; {
    User.getUserById(id, (err, user) =&gt; {
      done(err, user);
    });
  });
  
  router.post('/', (req, res, next) =&gt; {
    passport.authenticate('local', {
      successRedirect: '/',
      failureRedirect: '/toSignInPage',
      failureFlash: true
    })(req, res, next);
  });
  
  module.exports = router;
  </code></pre>
  
  <p>user.js file</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  const bcrypt = require('bcryptjs');
  
  const UserSchema = new Schema({
    email: {
      type: String,
      required: true,
      trim: true
    },
    name: {
      type: String,
      required: true,
      unique: true,
      trim: true
    },
    password: {
      type: String,
      required: true,
      trim: true
    },
    profilePhoto: {
      originalemail: String,
      imagePath: String
    },
    token: String
  });
  
  const User = module.exports = mongoose.model('User', UserSchema);
  
  module.exports.registerUser = function(newUser, callback) {
    bcrypt.genSalt(10, (err, salt) =&gt; {
      bcrypt.hash(newUser.password, salt, (err, hash) =&gt; {
        if(err) {
          console.log(err);
        }
        newUser.password = hash;
        newUser.save(callback);
      });
    });
  };
  
  module.exports.getUserByEmail = function(email, callback) {
    const query = {
      email: email
    };
    User.findOne(query, callback);
  };
  
  module.exports.getUserById = function(id, callback) {
    User.findById(id, callback);
  };
  
  module.exports.comparePassword = function(candidatePassword, hash, callback) {
    bcrypt.compare( candidatePassword, hash, (err, isMatch) =&gt; {
      if(err) throw err;
      callback(null, isMatch);
    });
  };
  </code></pre>
  
  <p>I've initialized passport in my app.js file - session options and all that nice stuff.</p>
  
  <p>also my html(handlebars)for the form</p>
  
  <pre><code>       &lt;form method="post" action="/signInPage"&gt;
  
  
            &lt;label for="mail"&gt; Email &lt;/label&gt;
            &lt;input type="email" id="mail" name="email" /&gt;
            &lt;label for="password"&gt; Password&lt;/label&gt;
            &lt;input type="password" id="password" name="password"/&gt;
  
            &lt;button type="submit"&gt;Sign in&lt;/button&gt;
  
            &lt;p class="corp"&gt; &lt;a href="forgot.html"&gt;Forgot password?&lt;/a&gt; &lt;/p&gt;
  
          &lt;/form&gt;
  </code></pre>
  
  <p>Any help is appreciated on this. I've been stuck for a while debugging and I can't seem to figure out what I must have done wrong. please if I didn't properly format the question in an understandable format let me know.</p>