The error you are talking about is occur when you send response multiple time back .
If this is your whole block then see you are sending two response back one is inside user.validate function and other in password.validate .
// Check if sent user properties are valid
user.validate((err) => {
if (err) {
res.status(400).json({
error: 'User data not valid.',
});
}
});
// Check if sent password properties are valid
password.validate((err) => {
if (err || !password.arePasswordsEqual(req.body.password, req.body.passwordConfirm)) {
res.status(400).json({
error: 'Password data not valid.',
});
}
});
May be you can do like this
// Check if sent user properties are valid
user.validate((err) => {
if (err) {
res.status(400).json({
error: 'User data not valid.',
});
}else{
// Check if sent password properties are valid
password.validate((err) => {
if (err || !password.arePasswordsEqual(req.body.password, req.body.passwordConfirm)) {
res.status(400).json({
error: 'Password data not valid.',
});
}
});
}
});
This will help you .