express validator - custom password validator cannot read property of undefined express validator - custom password validator cannot read property of undefined mongoose mongoose

express validator - custom password validator cannot read property of undefined


This is a known bug, and will be fixed in the next release (current one being v5.2.0).
Custom validators that return nothing fail with that error.

To work around this, you can simply return true from your validator:

check('passwordconf').custom((value , { req }) => {    if (value !== req.body.password) {        throw new Error('Password confirmation is incorrect');    }    return true;})