Authentication middleware in Next.js

From the Next.js cheat sheet · Middleware · verified Jul 2026

Authentication middleware

typescript
// proxy.ts (Next.js 16 - was middleware.ts) - Authentication example
💡 Protect routes with auth checks
⚡ Redirect unauthenticated users
📌 Work with JWT tokens
🔥 Integration with auth libraries

More Next.js tasks

Back to the full Next.js cheat sheet