Overview
The Horse Trust backend uses several middleware functions for authentication, authorization, and request validation.Authentication Middleware
authenticate
Verifies JWT tokens in the Authorization header.Authorization Middleware
requireAdmin
Ensures the authenticated user has admin role.requireSeller
Allows access to users with seller or admin role.optionalAuth
Attempts to authenticate but allows the request to proceed even if no token is provided. Useful for public routes that can benefit from user context.Middleware Chain Examples
Admin-Only Route
Seller Route (Seller or Admin)
Public Route with Optional Auth
Auth-Protected Route
AuthRequest Type
The middleware extends Express’s Request type with user information:Rate Limiting Middleware
Defined inapp.ts, two rate limiters are configured:

