Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

node.js - Api Validation Failed

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

question from:https://stackoverflow.com/questions/65915862/api-validation-failed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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";
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...