Skip to content
>_VibeUnstuck

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. 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 /login once. Log the path and whether a user was found before you add another redirect.

  2. 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. 3

    Keep static files out of the matcher

    On Next.js 16 the file is proxy.ts. On older versions it is middleware.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. 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