set cookie and redirect in express -


i'm trying set cookie response , redirect user if haven't been verified (inside route)

//add jwt token on successful login res.cookie('jwt', user.token) console.log(user) if(user.security.active === false ){   res.status(401).json({error: 'your account has been deactivated'}) } //if user.security.verified == true if(user.security.verified === false){    res.redirect('/verify'); }  if(user.security.approved === false) {    res.redirect('/approval') }  res.redirect('/') 

i error on server error: can't set headers after sent.

does mean can't use redirect when set cookie?

wait sorry, added return before each res , works should

if contribute comment further explain please do.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -