Browse/Next.js/Edge Middleware Auth Redirect
Edge Middleware Auth Redirect
Next.js
$19 · Pro
Redirect unauthenticated requests before they reach a protected route.
middleware.ts
return NextResponse.redirect(new URL('/login', request.url))
Unlock the full snippet
This is a Pro snippet — get all-access for $19, or unlock just this one snippet for $1.