title: Why can't I connect to my passport middleware?
body: <p>I'm trying to set up passport for authentication, but I can't figure out why I can't connect. The post request is received, but I'm not sure why the authenticate function isn't working or how to debug it.  The post request is received by the router here</p>
  <pre><code>const express = require('express');
  const passport = require('passport');
  const jwt = require('jsonwebtoken');
  
  const router = express.Router();
  
  require(&quot;../auth/auth&quot;);
  
  router.post('/register', (req, res, next) =&gt; {
    console.log(&quot;Posted request recieved&quot;);
    passport.authenticate('register', { session: false }, async (err, user, info) =&gt; {
      console.log(&quot;Worked&quot;);
      res.send(&quot;Worked&quot;);
    })
  });
  
  module.exports = router;
  </code></pre>
  <p>And my passport middleware is defined here in /auth/auth:</p>
  <pre><code>const passport = require('passport');
  const localStrategy = require('passport-local').Strategy;
  
  module.exports = function(passport) {
    passport.use('register',
        new localStrategy(
          {
            usernameField: 'username',
            passwordField: 'password',      
            passReqToCallback : true 
          },
          (async (req, username, password, done) =&gt; {
            try {
                console.log(&quot;Connected!&quot;);
            }
            catch(error) {
                console.log(&quot;Error: &quot; error)
            }
            finally { return done(null) }
          })
        )
      );
  </code></pre>
  <p>The error I'm receiving is that the callback function is never called. The post request is received, but it never calls the ansnnc function I defined in the passport middleware. &quot;Connected!&quot; is never printed. I'm not sure how to fix this so any help would be appreciated.</p>