title: Passport facebook doesn't create new user and times out
body: <p>I'm using passport with multiple strategies (JWT, Google and Facebook). All work fine except Facebook, when an existing user tries to login. In this case it just times out and I get a 504.</p>
  <p>It tries to call <a href="https://api.example.com/users/facebook/callback/?code=.." rel="nofollow noreferrer">https://api.example.com/users/facebook/callback/?code=..</a>. before I get the timeout error.</p>
  <p>I tried the exact same logic from my Google strategy, where everything works fine, but it doesn't help. I tried different online tutorials but none of them worked either.</p>
  <p>So what am I doing wrong?</p>
  <p><strong>Passport.js config - Facebook code block</strong></p>
  <pre><code>function(passport) {
  
    passport.serializeUser((user, cb) =&gt; {
      cb(null, user);
    });
    
    passport.deserializeUser((user, cb) =&gt; {
      cb(null, user);
    });
  
    passport.use(new FacebookStrategy({
      proxy: true,
      clientID: keys.facebook.clientID,
      clientSecret: keys.facebook.clientSecret,
      callbackURL: &quot;https://api.example.com/users/facebook/callback&quot;,
      profileFields: ['id', 'displayName', 'email']
    },
    async (accessToken, refreshToken, profile, done) =&gt; {
  
      const { email, first_name } = profile._json;
  
      try {
        const oldUser = await User.findOne({ email: email });
  
        if (oldUser) {
          return done(null, oldUser);
        }
      } catch (err) {
        console.log(err);
        return done(null, false);
      }
  
      // register user
      try {
        const newUser = await new User({
          facebook: true,
          email: email,
          name: first_name,
          verified: true,
        }).save();
  
        done(null, newUser);
      } catch (err) {
        console.log(err);
        return done(null, false);
      }
  }
  ))
  }
  </code></pre>
  <p><strong>User auth route</strong></p>
  <pre><code>// FACEBOOK
  router.get(&quot;/facebook&quot;, passport.authenticate(&quot;facebook&quot;));
  
  router.get(&quot;/facebook/callback&quot;, generalTooManyRequests, passport.authenticate(&quot;facebook&quot;), (req, res) =&gt; {
    const referer = req.cookies[&quot;Origin&quot;]
    let redirectURL
  
    // login did NOT work!
    if (!req.user) {
      redirectURL = &quot;https://app.example.com/login/fehler-facebook&quot;
      if (referer === &quot;website&quot;) {
        redirectURL = &quot;https://example.com/login/?fehler-facebook&quot;
      }
      res.redirect(redirectURL)
    } 
    // login did work!
    else {
      redirectURL = &quot;https://app.example.com/callback/token=&quot;
      if (referer === &quot;website&quot;) {
        redirectURL = &quot;https://example.com/callback/?token=&quot;
      }
  
      const tokenObject = utils.issueJWT(req.user);
      res.redirect(redirectURL + tokenObject.token)
    }
  });
  </code></pre>