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('local', {failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
Full Error:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:644:11)
Am I missing something? Not sure why this error is happening. I’m still able to use the app, I just dont want the error.
You are redirecting the user so serializeUser function is being called twice. And in
be sure to add this else or it gets called twice, thus sending the headers twice and causing error. Try this: