node.jshttp-redirectpassport.jspassport-facebook

Can't redirect while using passport-facebook login startegy


I am using the passport-facebook package to redirect the user to the home page after successful login with Facebook. The redirect is not working properly.

The following code doesn't work.The callback API is executed, but nothing is happening after that.

 app.get('/auth/facebook/callback', passport.authenticate('facebook', {
     successRedirect: config.facebookAuth.redirect,
     failureRedirect: config.facebookAuth.failureRedirect
 }));

What is wrong here?

But while using the following code,it works fine:

 app.get('/auth/facebook/callback', function (req,res){
     res.redirect(config.facebookAuth.redirect);
 });

Solution

  • The error was due to the fact that my passport.serializeUser() was not serializing properly due to which it wasn't successfully redirecting.