Service Layer high complexity Shared Component backend
1
Dependencies
0
Dependents
18
Entities
0
Integrations

Description

Next.js middleware that runs on every protected API route (`/api/v1/...`) to validate the JWT access token and enforce role-based access at the backend. Extracts the role and organisation ID claims from the token and rejects requests that lack the required role for the requested endpoint. Ensures that mobile app UI enforcement is backed by server-side validation.

Feature: Role-Based Access Control

permission-validation-middleware

Responsibilities

  • Intercept all requests to protected API routes before handler execution
  • Verify JWT signature and expiry
  • Extract role and organisation ID claims from the verified token
  • Reject requests with HTTP 403 when the role is insufficient for the endpoint
  • Enforce tenant isolation by validating the organisation ID matches the requested resource scope

Interfaces

middleware(request: NextRequest) -> NextResponse
extractClaims(token: string) -> JwtClaims
requireRole(roles: UserRole[]) -> MiddlewareHandler
requireOrgAccess(orgId: string) -> MiddlewareHandler
verifyToken(token: string) -> JwtClaims | null

Relationships

Dependencies (1)

Components this component depends on