validate a password with express-validator
I found the answer
req.assert('password2', 'Passwords do not match').equals(req.body.password1);var mappedErrors = req.validationErrors(true);
This one works!
req.checkBody('password2','Passwords do not match.').equals(req.body.password1);var errors = req.validationErrors();
notice the use of checkBody()
in this case
This is the answer I found
const { body } = require('express-validator/check');app.post('/user', body('passwordConfirmation').custom((value, { req }) => {if (value !== req.body.password) { throw new Error('Password confirmation does not match password'); } }), (req, res) => {// Handle the request});`
check this document https://express-validator.github.io/docs/custom-validators-sanitizers.html