validationResult is not working well and returns typeError validatorResult is not a function but the problem still continues
ValidatorFields.js file:
const { validationResult } = require("express-validator");
const validatorFields = (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json(errors);
}
next();
};
module.exports = validatorFields;
auth.js file:
const { Router } = require("express");
const { check } = require("express-validator");
const routes = Router();
const { validEmail } = require("../helpers/validatorDB.js");
const validateFields = require("../helpers/ValidatorFields.js");
const AuthController = require("../controllers/authController.js");
routes.post(
"/register",
[
check("name", "Name is required").not().isEmpty(),
check("email", "Invalid email").isEmail(),
check("password", "Password must have more than 8 characters").isLength({
min: 8,
}),
check("email").custom(validEmail),
validateFields,
],
AuthController.register
);
routes.post(
"/login",
[
check("email", "Invalid email").isEmail(),
check("password", "Password is required").not().isEmpty(),
],
AuthController.login
);
module.exports = routes;
return json data is:
errors": [
{
"type": "field",
"value": "taner@gmail.com",
"msg": "this.validator is not a function",
"path": "email",
"location": "body"
}
]
I check for missing or incorrectly defined functions called this.validator but still the same problem persists.I updated your express-validator version but it doesn't work. If the error still persists, I used the current version of express-validator and it still didn't work.Am I wrong? Any help is much appreciated. "express-validator - req.this.validator is not a function is not a function"
json data is:
{
"name":"tanertaner",
"email": "taner@gmail.com",
"password":"tanertaner"
}
result data:
{
"errors": [
{
"type": "field",
"value": "taner@gmail.com",
"msg": "this.validator is not a function",
"path": "email",
"location": "body"
}
]
}
and check("name", "Name is required").not().isEmpty(),
TypeError: check is not a function \routes\auth.js:11:5) is a result check not null
But the login process is successful, I only get a registration error.