📄️ Introduction to Middleware in JWT Smith
JWT Smith provides built-in middleware to simplify authentication and authorization in your application. These middleware functions help verify JWTs, extract user information, and enforce role-based access control (RBAC) seamlessly.
📄️ validateJwtCookieMiddleware
The validateJwtCookieMiddleware checks for the presence of access and refresh tokens in the request cookies. If neither token is found, it throws an error. If tokens are found, it validates or refreshes them using the provided token generation handler and token storage.
📄️ validateJwtHeaderMiddleware
The validateJwtHeaderMiddleware is similar to the validateJwtCookieMiddleware but has additional configurations for handling JWTs in request headers. This middleware extracts the JWT from the specified header, validates it, and optionally refreshes it if needed.
📄️ roleBasedAuthenticationMiddleware
The roleBasedAuthenticationMiddleware enforces role-based access control (RBAC) for API endpoints by verifying user roles and their associated permissions before granting access.