Skip to content

feat: implement Joi request validation middleware for auth routes (#50) (Apertre3.0)#70

Merged
akshay0611 merged 6 commits intoNsanjayboruds:mainfrom
Aditya-18849:feature/request-validation
Feb 18, 2026
Merged

feat: implement Joi request validation middleware for auth routes (#50) (Apertre3.0)#70
akshay0611 merged 6 commits intoNsanjayboruds:mainfrom
Aditya-18849:feature/request-validation

Conversation

@Aditya-18849
Copy link
Copy Markdown
Contributor

📝 Overview
This PR introduces a robust validation layer using Joi to intercept requests before they reach the controllers. It ensures that only valid data is processed by the backend, improving security and providing clear feedback to the frontend.

Key Implementation Details
Library: Used joi for schema definition as discussed in #50.

Middleware: Created validateRequest.js which acts as a "traffic cop."

Feature: Enabled abortEarly: false so the user receives ALL validation errors at once (instead of just the first one).

Response: Returns a clean 400 JSON response with an array of error messages.

Schemas: Created validators/authSchemas.js containing strict rules for:

registerSchema: Enforces name length (min 3), valid email, and password length (min 6).

loginSchema: Enforces valid email and non-empty password.

Routes: Applied the middleware to the /registration and /login routes in authRoutes.js.

How To Test :

Pull this branch and run npm run dev in the backend.

Send a POST request to /api/auth/registration with invalid data (e.g., short name, bad email).

Expected Response :{
"success": false,
"message": "Validation Error",
"errors": [
"Name must be at least 3 characters",
"Please provide a valid email address"
]
}

@Aditya-18849
Copy link
Copy Markdown
Contributor Author

Hi @akshay0611 This is the PR for the issue no : #50
i have implemented Joi request validation over zod because Joi is industry standard choice and also in the previous work that i have done in .js and hence javascript files are built specifically for js

The PR is ready for review , kindly check it out!!

@Aditya-18849
Copy link
Copy Markdown
Contributor Author

Hi @akshay0611 there were some merge conflicts which got resolved , kindly check this out and verify the pull request

@Aditya-18849
Copy link
Copy Markdown
Contributor Author

@akshay0611 ??

@akshay0611
Copy link
Copy Markdown
Collaborator

akshay0611 commented Feb 14, 2026 via email

Copy link
Copy Markdown
Collaborator

@akshay0611 akshay0611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the request-validation work - good direction overall. I re-verified PR #70 locally and found a few blockers before merge:

  1. backend/package-lock.json is currently malformed JSON (the @standard-schema/spec block is incomplete), so install/update flows will fail.
  2. backend/routes/authRoutes.js imports ../controller/authController.js, but the tracked file is authcontroller.js; this can fail on case-sensitive environments (Linux/CI/prod).
  3. Validation rules are inconsistent: Joi registration allows password length >=6, while controller logic still enforces >=8.

Please fix these and I can re-review quickly.

@Aditya-18849 Aditya-18849 force-pushed the feature/request-validation branch from b6c73fd to c5a6445 Compare February 15, 2026 16:21
@Aditya-18849
Copy link
Copy Markdown
Contributor Author

hi @akshay0611 i have the pr ready for review and solved the backend merge conflicts , kindly check this out

@akshay0611
Copy link
Copy Markdown
Collaborator

Thanks for the update @Aditya-18849 . I re-verified PR #70 at the latest head and here’s the current status:

  • Fixed: backend/package-lock.json is now valid JSON.
  • Fixed: import casing in authRoutes.js now uses authcontroller.js.
  • Not fixed: password validation is still inconsistent:
    • registerSchema allows min(6) in backend/validators/authSchemas.js
    • controller enforces password.length < 8 in backend/controller/authcontroller.js

Additional blockers introduced in the latest update:

  1. backend/.gitignore contains unresolved merge conflict markers (<<<<<<<, =======, >>>>>>>).
  2. backend/node_modules/.package-lock.json is now tracked in the PR (files under node_modules must not be committed).

Please address these remaining issues, then I can do a quick final re-review.

@Aditya-18849
Copy link
Copy Markdown
Contributor Author

Hi @akshay0611 , the PR is ready and ready for review

@akshay0611 akshay0611 self-requested a review February 18, 2026 03:41
Copy link
Copy Markdown
Collaborator

@akshay0611 akshay0611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress on the validation updates, and thanks for addressing the earlier blockers.

I am merging this PR now.

One non-blocking cleanup point for future PR quality: the Swagger JSDoc block in backend/routes/authRoutes.js still has formatting/content issues (for example -QP email and YAML indentation). Runtime works, but malformed Swagger comments can break or degrade generated API docs.

Best practice to follow going forward:

  1. Keep Swagger YAML indentation strict and consistent.
  2. Validate field entries carefully (avoid typos in schema keys/items).
  3. Quickly verify /api-docs renders correctly before requesting review.

@akshay0611 akshay0611 merged commit e455440 into Nsanjayboruds:main Feb 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend] Implement Request Validation Middleware (Joi/Zod) (Apertre3.0)

2 participants