I want to redirect to another page after successful login , but it show me this message "Cannot set headers after they are sent to the client", i know i should have place the res.redirect somewhere else but i really struggling with this one
router.get('/login',(req,res)=>{
res.render('login')
})
router.post('/login',(req,res)=>{
user.findOne({
where: {
userName : req.body.userName
}
})
.then(userInfo=>{
if(userInfo){
if(bcrypt.compareSync(req.body.password,userInfo.password)){
const token = jwt.sign(userInfo.dataValues,process.env.SECRET_KEY,{
expiresIn:1440
})
res.send(token)
res.redirect('/home')
}
else {
res.status(400).json({error:'user doesnt exist'})
}
}
}
)
})
res.send(token)before the redirect. Maybe there's another way to do this? Is it possible to do this after? - user10957435