Api Validation Failed

Viewed 336

When I try to validate the user it does not work.‘Validate register input’ does not helps me to validate the user. The payload and output from Postman are: 1

Also, When I try

console.log(req.body);

inside the post request the output is: in the attached image

Here is my complete code link : https://codesandbox.io/s/github/naima-shk/Twitter-Clone

2 Answers

I checked your code and it seems you have a logic error in your validation logic where you apply isEmpty:

 if(!Validator.isEmpty(data.handle)){
        errors.handle ="Handle field is required";
 }
 if(!Validator.isEmpty(data.email)){
       errors.email ="Email field is required";
 }

It should be the other way around (note that you have this error for other fields as well, so check those too):

 if(Validator.isEmpty(data.handle)){
        errors.handle ="Handle field is required";
 }
 if(Validator.isEmpty(data.email)){
       errors.email ="Email field is required";
 }

You are not passing correct value in email param, so of course it would throw validation error. Do it something like abc@gmail.com

Related