title: passport authentication callback not calling passport middleware
body: <p>I am trying to test if a GET request to a specific route is protected by using JSON Web Tokens with passport JwtStrategy; however, it seems like the <code>passport.use</code> middleware function I have in my <code>server.js</code> file is not executing. The console.log I have in there never shows up in my shell/terminal. My login route works, but not the profile route. I am using postman and I entered <code>http://localhost:3000/profile</code> for the GET method and in the <code>Headers</code> tab I chose Authorization for Key and for the Value I copied and pasted the long JSON web token string, but it keeps saying unauthorized. That is because my passport.use function is never getting executed.</p>
  
  <p>//Server.js file</p>
  
  <pre><code>var JwtStrategy = require("passport-jwt").Strategy;
  var ExtractJwt = require("passport-jwt").ExtractJwt;
  
  var User = require("../models/user");
  var config = require('./secret');
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  let options = {};
  //pass token back and forth
  options.jwtFromRequest = ExtractJwt.fromAuthHeader();
  options.secretOrKey = config;
  passport.use(new JwtStrategy(options, (jwt_payload, done) =&gt; {
    *******************************************
    //this console log doesn't show up in shell which makes be believe its never getting here
    *******************************************
    console.log("JWT PAYLOAD", jwt_payload)
    User.getUserById(jwt_payload._id, (err, user) =&gt; {
      if(err){
        return done(err, false);
      }
  
      if(user){ //null for error
        return done(null, user);
      }else{
        return done(null, false);
      }
    });
  }));
  </code></pre>
  
  <p>//Routes file where the passport.authenticate callback is called</p>
  
  <pre><code>var passport = require('passport');
  var jwt = require('jsonwebtoken');
  var secret = require('../config/secret')
  
  var User = require('../models/user');
  
  router.post('/login', (req, res) =&gt; {
      var username = req.body.username;
      var password = req.body.password;
      console.log("SECRET2", secret);
      console.log("SECRET", secret.secret);
      User.getUserByUsername(username, (err, user) =&gt; {
          if(err){
              throw err;
          }
          if(!user){
              return res.json({ success: false, msg: "User not found"});
          }
  
          User.comparePassword(password, user.password, (err, isMatch) =&gt; {
              if(err){
                  throw err;
              }
              if(isMatch){
                  var token = jwt.sign(user, secret.secret, {
                      expiresIn: 604800 //1 week in seconds, token expires and requires to log back in
                  });
  
                  console.log('TOKEN IN LOGIN ROUTE', token)
  
                  res.json({
                      //tokens are then stored in local storage or cookie
                      success: true,
                      token: 'JWT ' + token,
                      user: {
                          id: user._id,
                          name: user.name,
                          username: user.username,
                          email: user.email
                      }
                  });
              }else{
                  return res.json({ success: false, msg: "Incorrect password"});
              }
          });
      });
  });
  
  router.get('/profile', passport.authenticate('jwt', {session:false}), (req, res) =&gt; {
      res.json({user: req.user});
  });
  </code></pre>
  
  <p>//User model</p>
  
  <pre><code>var mongoose = require('mongoose');
  var bcrypt = require('bcryptjs');
  
  var Schema = mongoose.Schema;
  
  var UserSchema = new Schema({
    name: {
      type: String,
      trim: true,
      required: "First Name is Required"
    },
    email: {
      type: String,
      required: true
    },
    username: {
      type: String,
      required: true
    },
    password: {
      type: String,
      required: true
    }
  });
  
  var User = mongoose.model("User", UserSchema);
  
  module.exports = User;
  
  //Alternate syntax for exporting Schema
  // var User = module.exports = mongoose.model("User", UserSchema);
  
  module.exports.getUserById = function(id, callback){
      User.findById(id, callback);
  }
  
  module.exports.getUserByUsername = function(username, callback){
      var query = { username: username }
      User.findOne(query, callback);
  }
  
  //Custom User model function that will take in the newUser object and hash the password.
  module.exports.addUser = function(newUser, callback){
      bcrypt.genSalt(10, (err, salt) =&gt; {
          bcrypt.hash(newUser.password, salt, (err, hash) =&gt; {
              if(err){
                  throw err
              }
  
              newUser.password = hash;
              newUser.save(callback);
          });
      });
  }
  
  module.exports.comparePassword = function(password, hash, callback){
      bcrypt.compare(password, hash, (err, isMatch) =&gt; {
          if(err){
              throw err
          }
          callback(null, isMatch);
      });
  }
  </code></pre>
  
  <p>Update: 
  I tried putting a space after 'JWT' in for the value for Authorization in the postman, but it still does not work and the console log is not showing. Is it because I am somehow not exporting or linking the <code>passport.use</code> I have defined in my <code>server.js</code> to my GET '/profile' route in my routes file?</p>
  
  <p>Update 2: Added model and Login route</p>