Build Next.js 15 middleware for JWT validation, role-based route protection, geo-redirects, and A/B testing at the edge.
Act as a Next.js 15 middleware expert. Create middleware.ts for [PROTECTED_ROUTES]. Validate JWT from [AUTH_COOKIE]. Redirect unauthenticated users to [LOGIN_PATH]. Implement role-based access for [ROLE_ROUTES_MAP]. Add geo-redirect logic for [GEO_RULES]. Use matcher config to skip [PUBLIC_ASSETS].
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Llama 4.
List protected routes, auth cookie name, login path, role-route mapping, geo-redirect rules, and public asset paths to skip.
Initial release
Sign in and download this prompt to leave a review.