title: Node Express: Passport JWT middleware not being executed
body: <p>When I use 'passport.authenticate('jwt', { session: false })' in a route, it returns 'Unauthorized'. The passport middleware seems not working. I don't know what is wrong! In the header I'm using the 'Authorization: JWT MY_TOKEN'.</p>
  
  <p><strong>app.js file</strong></p>
  
  <pre><code>// ...code
  
  const app = express();
  app.use(bodyParser.json());
  app.use(passport.initialize());
  require('./config/passport')(passport); // passport middleware file
  
  app.use('/api/auth', auth); // routes
  app.use('/api/lists', lists); // routes  
  </code></pre>
  
  <p>.</p>
  
  <p><strong>Passport middleware file:</strong></p>
  
  <pre><code>const { Strategy, ExtractJwt } = require('passport-jwt');
  const User = require('../models/User');
  const keys = require('./keys');
  
  module.exports = (passport) =&gt; {
      const opts = {};
      opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
      opts.secretOrKey = 'MYSECRETKEY';
  
      // HERE IS EXECUTED! &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  
      passport.use(new Strategy(opts, function(jwt_payload, done) {
          // HERE IS NOT BEING EXECUTED! &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  
          User.findOne({_id: jwt_payload.id}, function(err, user) {
              if (err) {
                  return done(err, false);
              }
              if (user) {
                  return done(null, user);
              } else {
                  return done(null, false);
              }
          });
      }));
  }
  </code></pre>
  
  <p>.</p>
  
  <p><strong>Login route (creating the token):</strong></p>
  
  <pre><code>router.post('/login', (req, res, next) =&gt; {
    const { email, } = req.body;
  
    User.findOne({ email: email }, { password: 0 }, (errQuery, resUser) =&gt; {
      const token = jwt.sign({_id: resUser.id}, 'MYSECRETKEY');
  
      const responseData = {
        status: true,
        token: `JWT ${token}`
      };
  
      res.send(responseData);
    });
  });
  </code></pre>