title: passport is throwing user.authenticate is not a function
body: <p>I know this question has been asked before,but I couldn't found a proper answer.
  Here is the console error.</p>
  
  <pre><code>TypeError: user.authenticate is not a function
  at /home/sinnedde/WebstormProjects/web-services/config/strategies/local.js:24:23
  </code></pre>
  
  <p>Here is local.js used to check if the username and password are correct.</p>
  
  <pre><code>var passport = require('passport'),
  LocalStrategy = require('passport-local').Strategy,
  User = require('mongoose').model('User');
  
  module.exports = function () {
  passport.use(new LocalStrategy(function (username, password, done) {
      User.findOne({
          username: username
      }, function (err, user) {
          if (err) {
             return done(err);
          }
          if (!user) {
              return done(null, false, {
                  message: 'Invalid Username or Password'
              });
          }
          if (!user.authenticate(password)) {
              return done(null, false, {
                  message: 'Invalid Username or Password'
              });
          }
          return done(null, user);
      });
   }));
  };
  </code></pre>
  
  <p>Here is the signin method in the controller.</p>
  
  <pre><code>exports.signin = function (req, res, next) {
  passport.authenticate('local', function (err, user, info) {
     if (err || !user) {
         res.send(info);
     } else {
         res.json({
             status: 'true',
             message: 'Logged In'
         });
     }
   })(req, res, next);
  };
  </code></pre>
  
  <p>I am sending a request through postman. If the username is not valid I am getting proper response, but if the password is not valid, it's throwing above error. I don't know what's wrong. Please help.</p>