Skip to content

Instantly share code, notes, and snippets.

View FairyPenguin's full-sized avatar
🥷
Ninja Operator

Mahmoud Abd El-Aziz FairyPenguin

🥷
Ninja Operator
View GitHub Profile
@FairyPenguin
FairyPenguin / README.md
Created September 12, 2024 20:56 — forked from zachshallbetter/README.md
Middleware Examples

Next.js Middleware Examples

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.

Middleware Examples

  1. 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.