0

In reference to the similar question Error: Can't set headers after they are sent to the client

I was getting a similar error and was able to resolve it by adding

return res.redirect(.....);
next()

Could some one explain how this works? Can't seem to understand why this resolves the issue

Edit:Adding more the question

So i have the following route set up

router.get('/register', userDetail, auth.authorize({
    failureRedirect: '/login/failure'
}));

And under my userDetail.js

if(req.securityContext.actor.auth_state !== "LOGGEDIN"){
    return res.redirect(unifiedLoginUrl);
    //next();
}

The above code results in an error, can'set headers after sent

Community
  • 1
  • 1
Raj
  • 107
  • 1
  • 3
  • 11
  • Your code doesn't make sense (calling `next()` after returning). The error you were getting happens when you respond to the same request multiple times, but without you providing more context it's impossible to pinpoint the cause. – robertklep Jun 02 '15 at 07:37
  • You are right @robertklep, it doesnt make sense i have added more the question – Raj Jun 02 '15 at 17:36
  • Can you share more of `userDetail`, specifically what happens with the auth_state _is_ equal to `LOGGEDIN`. – robertklep Jun 02 '15 at 18:01

0 Answers0