A login that loops between your app and the sign-in provider

A login that bounces between your app and its sign-in provider, forever, almost always means the page the provider redirects back to navigates away before the app can exchange the one-time code for a session. The fix is to leave the callback URL alone until the app has read it, and to stop the app from starting another login from that same page.

What it looks like

That code is the whole point of the round trip: it is how the provider hands your app a session. If it is not used, the login did not happen.

How the redirect is supposed to work

The common pattern for browser apps is the OAuth 2.0 authorization code flow:

  1. Your app sends the browser to the provider, asking for a code. The request names a redirect URI, the address the provider may send the user back to.
  2. The user signs in at the provider.
  3. The provider redirects the browser to that redirect URI with a short-lived code and the state value your app sent. The code "MUST expire shortly after it is issued", and the client "MUST NOT use the authorization code more than once" (RFC 6749, section 4.1.2, checked 2026-11-06).
  4. Your app POSTs that code to the provider's token endpoint, with the same redirect URI, and gets tokens back (RFC 6749, section 4.1.3, checked 2026-11-06). state exists to protect step 3 from cross-site request forgery (RFC 6749, section 4.1.1, checked 2026-11-06); browser apps also use PKCE to tie the code to the app that asked for it (RFC 7636, checked 2026-11-06).

Steps 3 and 4 are the fragile part. The code lives only in the URL of the page the provider lands on, and it is only good once.

Why, precisely, the loop happens

Two ordinary pieces of app code collide:

  1. The callback route redirects. In a single-page app the callback address is a route, and that route is often written to bounce visitors onward — to a dashboard, or to a "you are signed in now" page. That redirect rewrites the address, and the code and state go with it.
  2. The auth library reads the callback late. The library parses the code from the page's URL when it finishes starting up, not at the instant the page paints. Auth0's browser library, for example, says handleRedirectCallback "must be called in order to complete the login flow" when "the browser is redirected from Auth0 back to your SPA" (Auth0 SPA SDK, checked 2026-11-06). If the URL has already been rewritten, there is no code left to read.

So the exchange never happens, the app believes nobody is signed in, and its "you must be signed in to see this page" guard sends the user back to the provider. Because the user still has a session at the provider, it answers instantly with a fresh code, and the same two steps fail again. Nothing in that cycle can break out on its own, which is why it is so fast.

How to confirm it in a minute

Open the browser's developer console before clicking sign in, and look at the Network panel, filtered to the provider's domain:

The console panel usually shows the library's own complaint — often an error about an invalid state or a missing transaction — instead of anything that names your redirect.

How to fix it

Check that it is fixed

See also

Glossary terms used on this page: Provider, Token.

Sources

All checked on 2026-11-06.


First version written with AI assistance, from a sign-in loop found while deploying a web app, and checked against the sources on 2026-11-06. Found a mistake? Fix it or open an issue. Text licensed under CC BY 4.0.