title: Express passport.authenticate() not working properly
body: <p>I'm having some issues with setting up passport. The information gets to the console.log(req.body) before passport.authenticate and then console.log(req.user) will return undefined afterwards. I will not hit the console.log inside of passport.use() function that is after the new LocalStrategy code. This does not though an error, nothing seems to happen. It will just enter the second if statement if(!user) and return me the status and error I outlined there. I have been trying to debug this for awhile and alas I'm no longer sure what the deal is.</p>
  <p>this is what my auth file looks like</p>
  <pre><code>router.post(&quot;/login&quot;, (req, res, next) =&gt; {
    console.log(req.body);
    passport.authenticate(&quot;local&quot;, function (err, user, info) {
      //console.log(req);
      //console.log(user);
      if (err) {
        //console.log(&quot;cp1&quot;);
        return res.status(400).json({ errors: err });
      }
      if (!user) {
        return res.status(400).json({ errors: &quot;No user found&quot; });
      }
  
      req.logIn(user, function (err) {
        console.log(&quot;cp1&quot;);
        if (err) {
          //console.log(&quot;cp3&quot;);
          return res.status(400).json({ errors: err });
        }
        return res.status(200).json({ success: `logged in ${user.id}` });
      });
    })(req, res, next);
  });
  </code></pre>
  <p>and this is what my passport.js file looks like</p>
  <pre><code>passport.serializeUser((user, done) =&gt; {
      done(null, user.id);
    });
  
    passport.deserializeUser((id, done) =&gt; {
      User.findById(id, (err, user) =&gt; {
        done(null, user);
      });
    });
    passport.use(
      new LocalStrategy((email, password, done) =&gt; {
        console.log(`${email}  , ${password}`);
        db.User.findOne({ email: email })
          .then((user) =&gt; {
            if (!user) {
            } else {
              if (user.password === password) {
                return done(null, user);
              } else {
                return done(null, false, { message: &quot;Wrong Password&quot; });
              }
            }
          })
          .catch((err) =&gt; {
            return done(null, false, { message: err });
          });
      })
    );
  
    passport.initialize();
    passport.session();
  </code></pre>