Passport Js "can't Set Headers After They Are Sent"
Getting this error when I successfully log in with passport JS. Trying to redirect to the home page once I log in. Code that does it: app.post('/login', passport.authenticate('l
Solution 1:
You are redirecting the user so serializeUser function is being called twice. And in
passport.use(new FacebookStrategy({
...
be sure to add this else or it gets called twice, thus sending the headers twice and causing error. Try this:
passport.use(new FacebookStrategy({
...
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's Facebook profile is returned to// represent the logged-in user. In a typical application, you would want// to associate the Facebook account with a user record in your database,// and return that user instead.
User.findByFacebookId({facebookId: profile.id}, function(err, user) {
if (err) { return done(err); }
if (!user) {
//create user User.create...return done(null, createdUser);
} else { //add this elsereturn done(null, user);
}
});
});
}
));
Post a Comment for "Passport Js "can't Set Headers After They Are Sent""