This Gist contains a collection of Next.js Middleware examples that demonstrate various use cases and scenarios for enhancing your Next.js applications. Middleware in Next.js allows you to intercept, modify, and control the flow of requests and responses, making it a powerful tool for building robust web applications.
- Authentication Middleware (
authenticationMiddleware.ts
):- Checks if the user is authenticated based on a session cookie.
- Redirects unauthenticated users to the login page.
- Ensures users have the necessary role to access protected routes.