fix(client): discard the urql client on logout - #4444
Open
gilgardosh wants to merge 1 commit into
Open
Conversation
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 16:18 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 16:18 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The refactor is small and cohesive, updates both call sites and tests, and the new behavior matches the stated logout safety goal without introducing inconsistencies.
Pull request overview
This PR hardens the client-side logout flow by ensuring the app discards the current urql Client (and any in-memory auth/caching state tied to it) before triggering the Auth0 logout redirect, preventing stale client state from surviving into a subsequent session within the same page lifetime.
Changes:
- Extracted
resetUrqlClientAndNotify()to centralize the “reset singleton + swap Provider client” behavior. - Updated
useLogoutto callresetUrqlClientAndNotify()before invoking Auth0logout(). - Un-skipped and expanded
useLogouttests to assert both the reset call and thereset → logoutordering; added a changeset entry.
File summaries
| File | Description |
|---|---|
| packages/client/src/providers/urql.tsx | Extracts resetUrqlClientAndNotify() and uses it from setBusinessScope to consistently reset+swap the Provider client. |
| packages/client/src/hooks/use-logout.ts | Resets urql client state before Auth0 logout redirect to avoid old client/token surviving logout. |
| packages/client/src/hooks/tests/use-logout.test.ts | Replaces the skipped Apollo-style resetStore test with urql-specific reset+ordering assertions. |
| .changeset/urql-logout-client-reset.md | Documents the behavior change as a patch release for @accounter/client. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
gilgardosh
force-pushed
the
claude/urql-step-3-error-toast-rollout
branch
from
September 10, 2026 16:31
cd99684 to
86e9ee7
Compare
gilgardosh
force-pushed
the
claude/urql-step-4-logout-reset
branch
from
September 10, 2026 16:31
2d722a8 to
6d61443
Compare
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 16:31 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 16:31 — with
GitHub Actions
Inactive
Base automatically changed from
claude/urql-step-3-error-toast-rollout
to
claude/urql-step-2-query-error-toast
September 10, 2026 17:11
Base automatically changed from
claude/urql-step-2-query-error-toast
to
main
September 10, 2026 17:14
`useLogout` cleared sessionStorage and handed off to Auth0 but left the urql client alone. The call that would have fixed it was commented out behind a `// TODO: clear URQL cache` and pointed at `urqlClient.resetStore?.()` — an Apollo method urql does not implement, so uncommenting it would have silently done nothing. Its test was parked as `it.skip` for the same reason. `useLogout` now calls `resetUrqlClientAndNotify()`, before `logout()` rather than after: `logout()` triggers a full-page redirect, so work queued behind it may never run. No visible effect today — the redirect tears down module state anyway, and the client holds no cache to leak. It stops being harmless once one exists: a normalized cache surviving a logout-then-login within a single page lifetime would serve the previous user's entities to the next one. Landing this before `@urql/exchange-graphcache` keeps that unreachable. `resetUrqlClientAndNotify` is extracted from `setBusinessScope`, which already paired `resetUrqlClient()` with the `onClientReset` swap. Clearing the singleton alone is not enough — everything already holding the old `Client` through the Provider keeps using it — and both callers need both halves, so they now share one function rather than each remembering the second call. The suite has no skipped tests for the first time: 371 passing, 0 skipped. Step 4 of the urql quick-wins sequence. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbrGL3NndzRiEwJkwHxnbm
gilgardosh
force-pushed
the
claude/urql-step-4-logout-reset
branch
from
September 10, 2026 17:20
6d61443 to
30a1c27
Compare
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 17:20 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 17:20 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 17:20 — with
GitHub Actions
Inactive
gilgardosh
temporarily deployed
to
accounter-fullstack
September 10, 2026 17:20 — with
GitHub Actions
Inactive
Contributor
|
The latest changes of this PR are not available as |
This was referenced Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 4 of 10 in the urql quick-wins sequence — tracking doc in #4437.
The problem
useLogoutclearedsessionStorageand handed off to Auth0, but left the urql client alone. The call that would have fixed it was commented out:resetStore()is an Apollo method. urql does not implement it — so uncommenting that line would have silently done nothing, and the optional call would have swallowed the mistake. Its test was parked asit.skipfor the same reason.The fix
useLogoutnow callsresetUrqlClientAndNotify()— beforelogout(), not after, becauselogout()triggers a full-page redirect and work queued behind it may never run.Why this matters later rather than now
Be clear about the severity: this has no visible effect today. The redirect tears down module state anyway, and the client currently holds no cache to leak.
It stops being harmless the moment a cache exists. A normalized cache surviving a logout-then-login inside a single page lifetime would serve the previous user's entities to the next one — and this is a multi-tenant app. Landing it now, before
@urql/exchange-graphcache, means that window never opens.The extraction
resetUrqlClient()alone only nulls the singleton. Everything already holding the oldClientthrough the Provider — every mounteduseQuery— keeps using it, along with its bearer token.setBusinessScopealready knew this and paired the reset with theonClientResetswap. That pair is nowresetUrqlClientAndNotify(), shared by both callers rather than each remembering to make the second call.Testing
Test-first: both new cases confirmed failing before the implementation, with the pre-existing Auth0 case still passing.
resetUrqlClientAndNotifyis called once['reset', 'logout'], locking in the redirect constraint aboveurql-client.test.ts's 14 auth cases exercisesetBusinessScopeand still pass through the refactored helper.The suite has no skipped tests for the first time — that
it.skipwas the last one.🤖 Generated with Claude Code
https://claude.ai/code/session_01TbrGL3NndzRiEwJkwHxnbm
Generated by Claude Code