-
Notifications
You must be signed in to change notification settings - Fork 626
TOKEN_REFRESHED loop on init with ECC P-256 signing key - SIGNED_OUT after 30 rapid refreshes #2126
Description
Describe the bug
On every page load, onAuthStateChange receives 30+ TOKEN_REFRESHED events in rapid succession (~100ms apart), followed by a SIGNED_OUT event that kills the session. This happens with zero Realtime channels active, with a clean localStorage, and regardless of supabase-js version (tested on 2.46.0 and 2.94.1).
Library affected
supabase-js
Reproduction
No response
Steps to reproduce
1.Have a Supabase project with ECC (P-256) as the active JWT signing key (migrated automatically by Supabase)
2.Create a React app with a standard AuthProvider using onAuthStateChange
3.Load the app with a valid session in localStorage
4.Observe console logs
1 INITIAL_SESSION event, then normal session behavior with TOKEN_REFRESHED firing at most once per hour.
Actual behavior
INITIAL_SESSION ← normal
TOKEN_REFRESHED ← fires BEFORE INITIAL_SESSION on some reloads
TOKEN_REFRESHED
SIGNED_OUT ← 5-6 seconds after INITIAL_SESSION
SIGNED_IN ← session re-established
TOKEN_REFRESHED ← rapid loop starts
TOKEN_REFRESHED ← ~100ms between each
TOKEN_REFRESHED ← 30+ times
...
SIGNED_OUT ← session killed by "refresh token already used"
Key observations
The loop starts before INITIAL_SESSION is processed — it originates inside the Supabase client initialization, not in application code
The loop occurs with zero Realtime channels active
The loop occurs with clean localStorage (all sb-* keys manually deleted)
A minimal test component with only 2 Realtime channels and no AuthProvider logic works perfectly — no TOKEN_REFRESHED loop
The project recently had its JWT signing key automatically migrated from Legacy HS256 to ECC (P-256) by Supabase
Supabase dashboard settings: Refresh token reuse interval: 30s, Detect and revoke compromised tokens: enabled
The SIGNED_OUT is caused by "refresh token already used" — multiple parallel refresh attempts consuming the same token within the reuse interval
System Info
@supabase/supabase-js: tested on 2.46.0 and 2.94.1 — same behavior on both
@supabase/auth-js: 2.94.1
@supabase/realtime-js: 2.94.1
Browser: Chrome (Windows)
JWT Signing Key: ECC (P-256) (migrated automatically, Legacy HS256 still present as "Previously used key")
React 18, ViteUsed Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Supabase JS Library issue and not an issue with the Supabase platform. If it's a Supabase platform related bug, it should likely be reported to supabase/supabase instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.