title: Express Router() and Passport Authenticate()
body: <p>I am playing around with Express(v4.15), Passport(v0.4.0), and Passport-JWT(v3.0.1).  I am using Node version 8.9.0.</p>
  
  <p>I can't seem to get Express.Router()s and my passport.authenticate() call to work properly.  What am I doing wrong here?</p>
  
  <p>./routes/user.js:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  router.get('/user', function (req, res) {
    res.send('Secured Page: user account settings');
  });
  
  module.exports = router;
  </code></pre>
  
  <p>./app.js:</p>
  
  <pre><code>var app = require('express')();
  var passport = require('passport');
  var passportJWT = require('passport-jwt');
  var jwt = require('jwt-simple');
  var Strategy = passportJWT.Strategy;
  var ExtractJWT = passportJWT.ExtractJwt;
  
  var userDB = require('./userdb');
  var config = require('./config/config');
  var params = {
    secretOrKeyProvider: function (req, rawJWT, done) { done(null, config.jwtSecret); },
    jwtFromRequest: ExtractJWT.fromAuthHeaderAsBearerToken()
  };
  
  var user = require('./routes/user');
  
  // ...
  
  var strategy = new Strategy(params, function jwtVerify (payload, done) {
    console.log('payload recieved', payload);
    // usually this would be a database call
    var user = userDB[_.findIndex(userDB, {id: payload.id})];
    if (user) {
      done(null, user);
    } else {
      done(new Error('User not found'), false);
    }
  });
  
  passport.use(strategy);
  
  //...
  
  app.use('/user', passport.authenticate('jwt', {session: false}), user);
  </code></pre>
  
  <p>This is what I get in Postman:
  <a href="https://i.stack.imgur.com/Ufr5j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ufr5j.png" alt="404 Error In Postman"></a></p>