0
Ich habe Probleme bei der Anzeige von Fehlern gleichzeitig, wenn comparePassword falsch ist und wenn req.check falsch eingefügt wurde. Kann mir bitte jemand bei der Verbesserung helfen ??Zeigt alle Fehler auf einmal an NodeJS
router.put('/changePassword', function (req, res, next) {
User.comparePassword(req.body.old, req.user.password, function (err, isMatch) {
req.check('old', 'Old password is required').notEmpty();
req.check('new', 'New password is incorrect').isLength({ min: 4 }).equals(req.body.newConfirm);
var errors = req.validationErrors();
if (err) throw err;
if (isMatch) {
bcrypt.hash(req.body.new, saltRounds, function (err, hash) {
if (err) {
console.log(err)
} else {
var newPassword = hash;
User.findOneAndUpdate({ _id: req.user._id },
{
$set: {
password: newPassword,
}
},
{
upsert: true
},
((newPassword) => {
res.send(newPassword)
})
)
}
})
} else {
res.json('Old password is wrong')
}}
)})