Skip to content

refactor(auth): extract authentication request validation into dedica…#825

Open
jikrana1 wants to merge 1 commit into
Userunknown84:mainfrom
jikrana1:refactor/extract-auth-validation-middleware-805
Open

refactor(auth): extract authentication request validation into dedica…#825
jikrana1 wants to merge 1 commit into
Userunknown84:mainfrom
jikrana1:refactor/extract-auth-validation-middleware-805

Conversation

@jikrana1

Copy link
Copy Markdown
Contributor

Closes #805

Problem description

The authRoutes.js file currently performed request validation directly inside the route definition, mixing validation logic with routing responsibilities. Additionally, the route file was inadvertently bloated with duplicate controller logic. This made the file large, unmaintainable, and violated the separation of concerns principle.

Proposed solution

Cleaned up authRoutes.js to strictly handle routing and applied dedicated validation middlewares.

Implementation details:

  • Removed all duplicate controller functions and business logic from authRoutes.js. (All controllers are now imported from ../controllers/authController.js).
  • Applied the existing pre-defined validators (registerValidation, loginValidation, forgotPasswordValidation, resetPasswordValidation) to the respective routes.
  • Cleaned up route definitions and properly applied protect middleware for protected endpoints.

Benefits

  • ✅ Improved separation of concerns: routing logic is now separated from controller and validation logic.
  • ✅ Increased code reusability: validators can now be easily reused across any future routes.
  • ✅ Reduced code duplication: the route file is now clean and focused.

Testing instructions

  1. Try to register with invalid data (e.g., missing email). The middleware should return a clear 400 Bad Request.
  2. Try to register with valid data. It should pass validation and reach the controller successfully.
  3. Try to access a protected route like /api/auth/me without authentication. It should return a 401 Unauthorized.

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Userunknown84 Userunknown84 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I see the changes that you shift that code to a particular file but the code removed from the existing files i show here and not see the files where the code is shifted but call the file in authroutes.js i see.

@jikrana1 jikrana1 force-pushed the refactor/extract-auth-validation-middleware-805 branch from 11758c0 to a1ace7a Compare July 14, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract authentication request validation into dedicated middleware

2 participants