Next.js Middleware
ELI5 — The Vibe Check
Next.js Middleware is like a bouncer that intercepts every request before it reaches your page. It runs at the edge (close to the user) and can redirect, rewrite, or modify requests on the fly. Need to check if someone's logged in before showing a page? Middleware's got you. Need A/B testing? Middleware winks and makes it happen.
Real Talk
Next.js Middleware executes before a request completes, running on the Edge Runtime. It can rewrite URLs, redirect users, set headers, and modify responses. It's commonly used for authentication checks, A/B testing, geolocation-based routing, and bot protection. It runs in every Vercel region for low latency.
When You'll Hear This
"Our middleware redirects unauthenticated users to the login page before the page even renders." / "We use Next.js middleware for A/B testing — users get assigned a variant at the edge."
Related Terms
Authentication (AuthN)
Authentication is proving you are who you say you are.
Edge Runtime
Edge Runtime is like having tiny copies of your server scattered around the world in every city, so your code runs right next to the user instead of in som
Next.js
Next.js is React's big sibling that adds superpowers like SSR, SSG, file-based routing, and API routes.
Vercel
Vercel is the magic platform that takes your frontend code and puts it on the internet in like 30 seconds.