How can I redirect the user to the login page and after the user logs in and based on a boolean variable again redirect the user to any url?
For instance:
app.get('*', (req, res, next) => {
if(req.path === ''){
res.redirect(302, '/login')
//After login in, I need to check the boolean flag and based on that redirect the user to a specific url
if(flag) {
res.redirect(302, '/error')
}
} else {
next();
}
})
With this implementation I'm getting the following error:
'Error [ERR_HTTP_HEADERS_SENT] Cannot set headers after they are sent to the client'
Any suggestion?