-
Notifications
You must be signed in to change notification settings - Fork 341
Enhancement: Add centralized express-validator system Issue #1234 #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Add centralized express-validator system Issue #1234 #1269
Conversation
@100NikhilBro is attempting to deploy a commit to the avdheshvarshney's projects Team on Vercel. A member of the Team first needs to authorize it. |
Thank you for submitting your pull request! We'll review it as soon as possible. For further communication, join our discord server https://discord.gg/tSqtvHUJzE. |
Hey @Avdhesh-Varshney , I’ve created a central validateRequest middleware which can now be used across all routes wherever we receive user input (req.body, req.params, or req.query). Additionally, I have prepared route-specific validators for the main route groups (user, auth, collection, collaborator). These validators are already built but not yet applied to the routes. You can integrate and use them as needed based on the requirements of each route. This setup ensures consistent input validation across the project and keeps controllers clean. |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@100NikhilBro By keeping the validators apart from the controllers, it will make the code to be confusing. |
@Avdhesh-Varshney I understand your point, but I kept validators separate to maintain better separation of concerns. |
@100NikhilBro No bro, Validation for a particular routes are not the same. You have taken some key parameters from those routes and validate them. It's not a good way to handle the validations of those routes. |
@Avdhesh-Varshney |
No, Right now I'm not having any other alternative for this |
Hi @Avdhesh-Varshney, |
Business logic should be executed after all the validations are passed. But I've already re-structure the code of all different routes from single file to each file for each route. So, I wanted to keep the validations to be in that file to be combined not separate and there will not be any clutter if doing this. Because all validations are at the start of the script, logic will be executed. |
@Avdhesh-Varshney On the other hand, express-validator is more suitable for simple field-level validations like checking the email format, password strength, or query parameters. It works well for flat structures, but is not ideal for validating complex or nested objects in critical routes. By keeping AJV validation at the top of each route file, we ensure that the business logic runs only after all validations pass, keeping the code clean, maintainable, and reusable. For less critical routes, we can skip validations to maintain efficiency, but for sensitive routes, AJV provides strict, reliable, and production-ready data integrity. |
Enhancement Request: Add Express Validators (Issue #1234)
Overview
This enhancement introduces a centralized request validation system for the Project Manager API using express-validator.
The goal is to validate all incoming user inputs consistently across different routes, keeping controllers clean and improving overall security.
1️⃣ Central Validator
middlewares/validateRequest.js
express-validator
.req.body
,req.params
, orreq.query
.Usage Example:
2️⃣ Route-specific Validators
Four main validator files have been created to cover key routes:
3️⃣ How It Works
validateRequest
middleware checks for validation errors.4️⃣ Future Usage
validateRequest
.✅ Benefits
Related Issue: Enhancement Request: Add express-validator #1234