processing / p5.js-web-editor

The p5.js Editor is a website for creating p5.js sketches, with a focus on making coding accessible and inclusive for artists, designers, educators, beginners, and anyone else! You can create, share, or remix p5.js sketches without needing to download or configure anything.
https://editor.p5js.org
GNU Lesser General Public License v2.1
1.37k stars 1.32k forks source link

Using Zod Library to validate inputs entered by the users in signup form and login forms. #2964

Closed rahulrana701 closed 4 months ago

rahulrana701 commented 8 months ago

Increasing Access

With this feature I will add input validations on every input of login and signup form so that the data entered by the user is correct when enters the database and do verification and other things. This validation will be done in both frontend and backend. Instead of creating some functions for the input validations we will use this library , this will make our code neat and clean as well.

Feature request details

Will use Zod Library to validate inputs entered by the users in signup form and login forms. I will add this library and make validations part in common folder so that it could be used in both frontend and backend.

Hi @lindapaiste please assign this to me I would like to work on this issue

lindapaiste commented 8 months ago

This validation will be done in both frontend and backend.

The current frontend validation logic is in https://github.com/processing/p5.js-web-editor/blob/2b993452f1b77dc1ddbe2d59e033d83056a1a0a8/client/utils/reduxFormUtils.js It could be cleaned up a lot and I'm sure that Zod (or Yup) can help with that.

Do we have any validation logic on the backend currently? @raclim All I'm finding is the duplicate check.

If you scroll down a bit on this page of the Mongoose documentation it shows how we can set properties like minLength, maxLength, match, etc. directly in our userSchema to get built-in validation. I'm not sure how that bubbles up into API responses and what those errors look like. It's definitely an option to use Zod to do validation on the req.body for particular handlers/controllers.

rahulrana701 commented 8 months ago

so @lindapaiste could you assign this issue to me , so that I could start working on this.

lindapaiste commented 8 months ago

I'm fine with it, but let's see if @raclim is on board.

AVtheking commented 8 months ago

@lindapaiste we can use joi validation in backend side for implementing clean validation

rahulrana701 commented 8 months ago

@lindapaiste we can use joi validation in backend side for implementing clean validation

@AVtheking I think using too many libraries for validation will create a mess , we should have a single library which could do validations in both frontend and backend.

rahulrana701 commented 8 months ago

@lindapaiste can I start working on this

rahulrana701 commented 8 months ago

@lindapaiste any updates should I start working on this , if the backend part is not clear I can add the frontend validation with zod for now and this will clear up a lot of unnecessary code , and when the backend part is clear we will add the validation there as well, If you are ok with it I will create a pr for this by today.

rahulrana701 commented 8 months ago

@lindapaiste @raclim can you guys give me any update on this ???

raclim commented 4 months ago

Thanks for raising this suggestion and providing an idea of what this might look like in your pull request! Sorry that it took a while to get to this. I personally feel that some of the logic that this library would be handling could be done internally rather than using a third-party for it. Maybe another way to approach this could be to create a helper file instead?

I'm going to close this issue and PR, but please feel free to make a new one with the suggested approach if you feel like that might work!