Skip to content

[I-004] [Tech Debt]: Deduplicate auth middleware (check_auth / check_customer_auth) #360

Closed

Description

@indpurvesh

Priority: Medium
Phase: Phase 1 (Code Quality)
Dependencies: #357, #359


📝 User Story

As a developer,
I want to eliminate the duplicated JWT validation logic in the auth middleware,
So that security fixes only need to be applied once and the code is DRY.


🎯 Scope & Requirements

  • Extract common JWT decode + validation logic from check_auth and check_customer_auth into a shared private function
  • Parameterize the middleware to differentiate admin vs. customer contexts via a generic or enum parameter
  • Remove the fully duplicated check_customer_auth function (lines 67-109 of auth_middleware.rs)

✅ Acceptance Criteria

  • Given auth_middleware.rs, When reviewed, Then there is exactly one JWT decode implementation.
  • Given an expired admin JWT, When sent to an admin-protected route, Then a 401 is returned with "Token expired" message.
  • All existing integration tests pass.

🛠️ Technical Context / Notes

  • Both functions in auth_middleware.rs are identical except for the function name. This is a classic DRY violation.

📋 Task Checklist

  • Extract shared JWT validation into a private helper
  • Refactor check_auth and check_customer_auth to call the shared helper
  • Run all integration tests

Metadata

Metadata

Assignees

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions