const express = require('express');
const { check, validationResult } = require('express-validator');
const router = express.Router();
router.post(
'/',
[
check('repeat_password')
.custom((value, { req }) => value === req.body.password)
.withMessage('Passwords do not match'),
],
(req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
res.send('User details okay');
}
);
module.exports = router;
// Postman
/*
{
"password": "aaaaaa1!",
"repeat_password": "aaaaaa1!"
}
*/
/*
run:
User details okay
*/