在将用户存储到数据库之前,我想检查该用户是否已注册,但当我尝试发布相同的已注册电子邮件时,它会显示正确的错误消息,但服务器停止说:error[err\u http\u headers\u sent]:发送到客户端后无法设置头
这是我的密码:
registerUser: (req, res) => {
let sql = 'SELECT * FROM registeredusers WHERE email = ?'
pool.query(sql, [email], (err, results) => {
if (results.length === 1) {
return res.status(400).json({
message: 'Email already exist.'
})
}
})
const saltRounds = 10
var fullname = req.body.fullname;
var email = req.body.email;
var userPassword = req.body.userPassword
bcrypt.hash(userPassword, saltRounds, (err, hash) => {
if (err) {
return res.status(500).json({
message: 'Internal error. Retry..'
})
}
userPassword = hash
userService.createUser(fullname, email, userPassword, (err, results) => {
if (err) {
res.status(500).json({
status: 'error',
error: err,
message: 'DataBase Connection Error'
});
}
return res.status(200).json({
status: 'success',
data: results
});
});
})
},
暂无答案!
目前还没有任何答案,快来回答吧!