ERR_TOO_MANY_REDIRECTS on login
Last verified:
The fix
ERR_TOO_MANY_REDIRECTS on login means the guard and the login page redirect to each other. Exclude the sign-in route and read the session from one place.
- 1
Exclude the public auth routes
Do not redirect
/login,/signup, or the auth callback. If the user is already signed in and hits/login, send them to the app once. If they are signed out and hit the app, send them to/loginonce. Log the path and whether a user was found before you add another redirect. - 2
Use one session source
On the server, use the Supabase SSR client (or your auth library’s server helper) and the refreshed cookie. Do not redirect based on a cookie name you guessed. Supabase splits the session across more than one cookie.
- 3
Keep static files out of the matcher
On Next.js 16 the file is
proxy.ts. On older versions it ismiddleware.ts. Exclude_next/static,_next/image, and public assets. Auth logic on those paths redirects the stylesheet and the page never finishes loading.export const config = { matcher: [ "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)", ], }; - 4
Clear a stuck cookie once
After you fix the redirect, clear site cookies for localhost and the deployed host. A half-written session cookie keeps failing the check that your new code would pass.
Why it happens
The guard treats the login page as private, so a signed-out user is redirected to login, which redirects to login again. Or the guard never sees a session, so a signed-in user is sent to login, and the login page sees a client-side session and sends them back to the app.
Those two checks have to use the same cookies. A client supabase.auth.getSession() and a server check that does not refresh cookies will disagree forever. A matcher that also runs on /_next/static can redirect CSS requests and look like a broken, looping page.
The next error you'll probably hit
Once this is fixed, the usual follow-up is The "middleware" file convention is deprecated. Please use "proxy" instead.. Next.js 16 still runs middleware.ts and prints this warning. The file is now proxy.ts, the export is proxy, and the runtime is Node.js.
Prompt to paste back into your AI tool
Paste this above the error.
The browser reports ERR_TOO_MANY_REDIRECTS between the app and /login. Do not remove auth. Do not redirect every path to /login. 1. Show the proxy or middleware condition and the login page’s own redirect. 2. Exclude /login, /signup, and the auth callback from the signed-out redirect. 3. Read the session the same way on both sides (for Supabase, @supabase/ssr plus a cookie refresh). 4. Exclude _next/static and images from the matcher. 5. Change only the guard and the login redirect.
Common questions
+The network tab shows dozens of 307s. Where do I look first?
The Location header. If it alternates between /login and /app, one side thinks you are signed in and the other does not. If every URL including CSS goes to /login, the matcher is too broad or the public routes are not excluded.
+Why does this happen only after adding Supabase middleware from a snippet?
The snippet redirects when getUser() is null, and it also protects the login route, or it returns a new response that dropped the refreshed cookies so getUser() is always null.
Related errors
- The "middleware" file convention is deprecated. Please use "proxy" instead.Next.js 16 still runs middleware.ts and prints this warning. The file is now proxy.ts, the export is proxy, and the runtime is Node.js.Cursorv0BoltNext.jsAuthOct 23, 2026
- auth() was called but Clerk can't detect usage of clerkMiddleware()auth() ran on a request that never passed through clerkMiddleware(). The file is in the wrong folder, the matcher skipped the route, or proxy.ts does not export the middleware.Cursorv0BoltAuthNext.jsOct 23, 2026
- Auth session missing after refreshAuth session missing: sign-in worked in the browser, but Next.js cannot see the Supabase cookie. Use the @supabase/ssr server client and refresh.CursorLovableBoltSupabaseAuthOct 14, 2026
- Error 400: redirect_uri_mismatchGoogle rejected the OAuth request because the redirect_uri it received is not one of the Authorized redirect URIs on that OAuth client. The deployed domain and the callback URL are different strings.CursorLovableBoltAuthSupabaseNov 11, 2026
- ERR_TOO_MANY_REDIRECTS after adding CloudflareThe browser loops as soon as the custom domain is proxied. Cloudflare's Flexible SSL talks to the host over HTTP, and the host redirects that HTTP request back to HTTPS.CursorLovableBoltVercelNext.jsOct 26, 2026
- Unexpected token '<' is not valid JSONUnexpected token '<' is not valid JSON: res.json() read HTML, usually a 404 or index.html. Check the status and URL first. A <!DOCTYPE body is not JSON.CursorLovableBoltNext.jsReactOct 16, 2026
- Error: NEXT_REDIRECTredirect() throws on purpose. A try/catch around it swallowed the throw, so the browser never navigated and the log shows NEXT_REDIRECT.Cursorv0BoltNext.jsReactOct 27, 2026
- ReferenceError: window is not definedwindow is not defined: Next.js read window, document, or localStorage on the server. Move that read into useEffect, or load the widget with ssr: false.Cursorv0BoltNext.jsReactOct 14, 2026