Reputation: 1
Everyone says to use an array but I want to see how to would do it in a function.
I have something like this
const checkPasswordConfirm = () => {
body('password-confirm').custom((value, { req }) => {
if(value !== req.body.password) {
throw new Error('Passwords confirmation does not match password')
}
})
}
Upvotes: 0
Views: 41
Reputation: 1596
Here, you need to return true of validation passes
enter code heconst { body } = require('express-validator');
const checkPasswordConfirm = () => {
return body('password-confirm').custom((value, { req }) => {
if (value !== req.body.password) {
throw new Error('Password confirmation does not match password');
}
return true; // Return true if validation passes
});
};
module.exports = checkPasswordConfirm;re
Upvotes: 0