title: Passport authenticate return json instead of redirect for angular
body: <p>I am trying to return json data from my successful sign-in or login. (This is so angular can grab it and do a redirect on the front end, not express redirecting on the back end).</p>
  
  <p>I have tried other answers I've seen on here and it makes sense and should work as far as I know. This answer in particular: <a href="https://stackoverflow.com/questions/26859349/can-you-authenticate-with-passport-without-redirecting">Can you authenticate with Passport without redirecting?</a> says it has working code but if I try the res.send I get the error below.   </p>
  
  <p>Here is my api:</p>
  
  <pre><code>app.post('/signup', passport.authenticate('local-signup', {
      successRedirect: '/loginSucceeded',
      failureRedirect: '/loginFailed'
    }
  ));
  
  app.get('/loginSucceeded', (req, res) =&gt; {
    res.json({message:'/posts'});
  });
  
  app.get('/loginFailed', (req, res) =&gt; {
    res.json({message:'/login'});
  });
  </code></pre>
  
  <p>at Promise._fulfill (C:\micromotion\node_modules\bluebird\js\release\promise.js:638:18)
      at PromiseArray._resolve (C:\micromotion\node_modules\bluebird\js\release\promise_array.js:126:19)
      at PromiseArray._promiseFulfilled (C:\micromotion\node_modules\bluebird\js\release\promise_array.js:144:14)
      at Promise._settlePromise (C:\micromotion\node_modules\bluebird\js\release\promise.js:574:26)
      at Promise._settlePromise0 (C:\micromotion\node_modules\bluebird\js\release\promise.js:614:10)
      at Promise._settlePromises (C:\micromotion\node_modules\bluebird\js\release\promise.js:693:18)
      at Async._drainQueue (C:\micromotion\node_modules\bluebird\js\release\async.js:133:16)
      at Async._drainQueues (C:\micromotion\node_modules\bluebird\js\release\async.js:143:10)
      at Immediate.Async.drainQueues (C:\micromotion\node_modules\bluebird\js\release\async.js:17:14)
      at runCallback (timers.js:672:20)
      at tryOnImmediate (timers.js:645:5)
      at processImmediate [as _immediateCallback] (timers.js:617:5)</p>
  
  <p>I have tried several other things like switching the success and failure redirect with a function and get the same error. Does that mean the error is within my passport strategy? I'm having a tough time understanding it, but it was pulled from a tutorial:</p>
  
  <pre><code> passport.use('local-signup', new LocalStrategy(
  
      {
        usernameField: 'email',
        passwordField: 'password',
        passReqToCallback: true // allows us to pass back the entire request to the callback
      },
  
  
      function(req, email, password, done) {
        var generateHash = function(password) {
          return bCrypt.hashSync(password, bCrypt.genSaltSync(8), null);
        };
  
        User.findOne({
          where: {
            email: email
          }
        }).then(function(user) {
          if (user)
          {
            return done(null, false, {
              message: 'That email is already taken'
            });
  
          } else
  
          {
            var userPassword = generateHash(password);
            var data =
            {
              email: email,
              password: userPassword,
              firstname: req.body.firstname,
              lastname: req.body.lastname
            };
  
            User.create(data).then(function(newUser, created) {
  
              if (!newUser) {
                return done(null, false);
              }
  
              if (newUser) {
                return done(null, newUser);
              }
            });
          }
        });
      }
    ));
  </code></pre>
  
  <p>Any my angular code that calls it, but shouldn't matter really:</p>
  
  <pre><code>  signup(data){
      return this.http.post('/api/signup', data)
        .toPromise()
        .then(response =&gt; {
          console.log(response);
         // this.router.navigate([response.url])
        });
    }
  </code></pre>