I have some error when i build auth in express js, there is Cannot set headers after they are sent to the client.
This is my code Before :
var dataUser = await user.findAll({
where: {
email: req.body.email,
password: req.body.password,
},
});
if (dataUser) {
res.send(dataUser);
// session
req.session.loggedin = true;
req.session.role = req.body.role;
}else{
req.flash('color', 'danger');
res.redirect('/login');
}
then i just add return on res.send and it’s work now
if (dataUser) {
return res.send(dataUser);
// session
req.session.loggedin = true;
req.session.role = req.body.role;
}