title: Passport authentication is not working in for Nodejs login using Jwt
body: <p>I'm working with the mean stack application and working on login and registration. When I used &quot;jwt&quot;, I couldn't get any output in the postman. The followings are my codes.</p>
  <p>index.router.js</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  
  const ctrlStudent = require('../controller/student.controller');
  
  router.post('/register', ctrlStudent.register);
  router.post('/authenticate', ctrlStudent.authenticate);
  
  module.exports = router; 
  </code></pre>
  <p>passportConfig.js</p>
  <pre><code>const passport = require('passport');
  const localStrategy = require('passport-local').Strategy;
  const mongoose = require('mongoose');
  
  var Student = mongoose.model('Student');
  
  passport.use(
      new localStrategy({ usernameField: 'email'},
      (username, password, done) =&gt; {
          Student.findOne({ email: username },
             (err, student) =&gt; {
                  if (err) 
                      return done(err);
          
                  else if (!student)
                      return done(null, false, {message: 'Invalid Email'})
               
                  else if (!student.verifyPassword(password))
                      return done(null, false, {message: 'Wrong credientials'})
               
                  else
                      return done(null, student);
              }); 
      })
  );
  </code></pre>
  <p>student.model.js</p>
  <pre><code>const mongoose = require('mongoose');
  const bcrypt = require('bcryptjs');
  const jwt = require('jsonwebtoken');
  
  var studentScheme = new mongoose.Schema({
          fullname:{
              type: String,
              required: 'Full name can not be empty'
          },
          email: {
              type: String,
              required: 'Email can not be empty',
              unique: true
          },
          password: {
              type: String,
              required: 'Password can not  be empty',
              minlength : [5,'Password must be atleast 5 character long']
          },
          saltSecret: String
  });
  
  
  // Regx validation for email
  studentScheme.path('email').validate((val) =&gt; {
      emailRegex = /^(([^&lt;&gt;()\[\]\\.,;:\s@&quot;]+(\.[^&lt;&gt;()\[\]\\.,;:\s@&quot;]+)*)|(&quot;.+&quot;))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      return emailRegex.test(val);
  }, 'Invalid e-mail.');
  
  
  studentScheme.pre('save', function (next) {
      bcrypt.genSalt(10, (err, salt) =&gt; {
          bcrypt.hash(this.password, salt, (err, hash) =&gt; {
              this.password = hash;
              this.saltSecret = salt;
              next();
          });        
      });
  });
  
  // Verify passowrd method
  studentScheme.methods.verifyPassword = function (password) {
      return bcrypt.compareSync(password, this.password);
  }
  
  // Generate Jwt
  studentScheme.methods.generateJwt = function () {
      return jwt.sign({_id: this._id},
          process.env.JWT_SECRET);
  }
  
  mongoose.model('Student', studentScheme);
  </code></pre>
  <p>app.js</p>
  <pre><code>require('./config/config');
  require('./models/db');
  require('./config/passportConfig');
  
  const express = require('express');
  const bodyParse = require('body-parser');
  const cors = require('cors');
  const passport = require('passport');
  
  const rtsIndex = require('./route/index.router');
  
  var app = express();
  app.use(bodyParse.json());
  app.use(cors());
  app.use(passport.initialize());
  app.use('/api', rtsIndex);
  
  
  app.use((err, req, res, next) =&gt; {
      if(err.name == 'ValidationError') {
          var valError = [];
          Object.keys(err.errors).foreach(key =&gt; valError.push(err.errors[key].message));
          res.status(422).send(valError);
      }
  });
  
  // start server 
  app.listen(process.env.PORT, () =&gt; console.log(`Server started at port : ${process.env.PORT}`));
  </code></pre>
  <p>student.controller.js</p>
  <pre><code>const mongoose = require('mongoose');
  
  const Student = mongoose.model('Student');
  
  
  module.exports.register = async (req, res, next) =&gt; {
      var student = new Student({
          fullname: req.body.fullname,
          email: req.body.email,
          password: req.body.password,
      });
  
      await student.save((err, doc) =&gt; {
          if (!err) {
              console.log(&quot;Saving the document...&quot;);
              res.send(doc);
          } else {
            if(err.code == 11000)
              res.status(422).send(['Duplicate email']);
            else
              return next(err);
          }
      });
  };
  
  module.exports.authenticate = (req, res, next) =&gt; {
      
      passport.authenticate('local', (err, student, info) =&gt; {
        
        if (err) return res.status(400).json(err);
        
        else if(student) return res.status(200).json({&quot;token&quot;: student.generateJwt()});
        
        else return res.status(404).json(info);
      })(req, res);
  }
  </code></pre>
  <p>I'm stacked at this point; the postman is not sending any response. Can you please someone help to overcome this issue?</p>