title: how to handle passport-facebook callback in angular client?
body: <p>I am developing a MEAN application. I am using passport for authentication- local, facebook and google strategies. </p>
  
  <p>I am using angularjs client. All the routing is handled at client. I am only consuming server data apis.</p>
  
  <p>When using passport-facebook strategy, I am using below code at node server as per passport docs.</p>
  
  <pre><code>    app.get('/auth/facebook',passport.authenticate('facebook-auth', { scope : ['email'] }));
      app.get('/auth/facebook/callback',passport.authenticate('facebook-auth', {
          successRedirect : '/home',
          failureRedirect : '/login',
          scope:['email']
      }));
  </code></pre>
  
  <p>Problem I am facing is when user click on "Sign in using Facebook" button</p>
  
  <pre><code>&lt;a href="/auth/facebook" class="btn"&gt;&lt;i class="fa fa-facebook"&gt;&lt;/i&gt; Sign in using Facebook&lt;/a&gt;
  </code></pre>
  
  <p>Client will access "/auth/facebook" route that will eventually redirect user to facebook page for validating user's credentials.</p>
  
  <p>After successful validation, user will be redirected to route "/home" as defined in "successRedirect" value.</p>
  
  <p>Now the thing is, I want to use custom callback function instead of defining redirects for success or failure. It will look like below:</p>
  
  <pre><code>app.get('/auth/facebook/callback',passport.authenticate('facebook-auth', function(err,user,info){
     if(err){
              throw err;
          }
          else if(user === 'userexists'){
              res.json({
                  'state':false,
                  'message':'User with this e-mail already exists'
              });
          }
          else{
              req.logIn(user,function(loginErr){
                  if(loginErr){
                      throw loginErr;
                  }
                  res.json({
                      'state':true,
                      'message':'You logged in successfully!'
                  });
              });
          }
   }));
  </code></pre>
  
  <p>The root problem I am facing here, I can not use above custom callback as Client is not calling the "auth/facebook/callback" route, it is called by facebook. 
  So, there is no success handler waiting to catch above callback's response at client side!!</p>
  
  <p>I want some way to get response in json form at client to eliminate server side redirection and also way to pass message and username to client after successful authentication by facebook.</p>
  
  <p>I am about to give up with passport. Hoping for any possible solution before removing a lot of code!</p>
  
  <p>Thanks</p>