Coalesce concurrent server-side refreshes of the same refresh token across clients
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- authentication
Research direction
Start by reading createServerClient in the ssr package and how it forwards global.fetch and the auth options to auth-js; then look at how refreshingDeferred and auth.lock dedupe refreshes inside a single client. The proposal offers two designs (a refreshCoalescing.reuseMs option vs. a default process-wide, token-keyed lock), and picking one is the first decision to write down before coding. Done means concurrent refreshes keyed on the refresh token share one Auth call and its response, with a test covering parallel requests reusing the same token.
Written by the indexing model from the issue text.
Description
Refresh tokens are single-use, and on the server every request builds its own createServerClient. When a browser sends several requests at once with an expired access token (a navigation plus prefetches, parallel route handlers, a few islands), each client refreshes the same refresh token. The first request rotates it. The others either get refresh_token_already_used or race inside the reuse interval, and the responses write different sessions into the same cookies.
auth-js dedupes refreshes inside one client (refreshingDeferred), but nothing is shared between server clients, so this can't be solved by the app without wrapping fetch.
What we do today
We pass createServerClient a global.fetch that coalesces POST /token?grant_type=refresh_token by refresh token, process-wide (a registry on globalThis, so separate module graphs in Next.js share it). The first call goes to Auth, concurrent callers wait for it, and the response is reused for 10 seconds so a request that arrives just after the rotation still gets the new session instead of a reuse error.
Proposal
An opt-in server-side refresh coalescing option, for example:
createServerClient(url, key, {
cookies,
auth: { refreshCoalescing: { reuseMs: 10_000 } },
})
or a pluggable lock (auth.lock exists for browsers) that createServerClient sets to a process-wide, token-keyed implementation by default. Either way, the key must be the refresh token (or a hash of it), never anything a client controls, and the shared response must only be replayed to callers that presented the same token.
- Dominant language
- TypeScript
- Stars
- 216
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from supabase/ssr
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
cookies.setAll loses its receiver for stateful cookie adaptersPossibly taken @PhuocOng claimed this 71 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 3/5 Half a day Newbie friendliness 56/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Stale host-only auth cookies survive a Domain migration and shadow the new sessionPossibly taken @RaphaelFakhri claimed this 30 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 66/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
prometheus/docs#3198 ·
Maintainers usually reply within 3 days
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
Chat: Copying a selection that includes the end of a message also copies the actions menu labelsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
suitenumerique/hub#176 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day