Repository navigation
fix(core): update useAuth after logging in with useLogin - #2683
Merged
Merged
Conversation
josephfusco
marked this pull request as ready for review
October 20, 2026 16:12
The viewer query used Apollo's cache, so logging in as a different user without a reload returned the previous user. A viewer that arrives after logging out is now ignored too.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Session transitions can expose stale viewer data, leave authentication state outdated, and prevent reauthorization redirects.
3 open issues
What changed in this PR
Updates useAuth to react to same-tab authentication changes, addressing the login synchronization issue in #1923.
Changes:
- Adds token-presence change notifications and subscribes
useAuth. - Fetches viewers from the network and guards responses after logout.
- Adds regression tests and documents automatic authentication updates.
| File | Description |
|---|---|
| packages/faustwp-core/tests/hooks/useAuth.test.ts | Tests login, logout, account switching, and skip behavior. |
| packages/faustwp-core/tests/auth/client/accessToken.test.ts | Tests listener notifications and unsubscribe behavior. |
| packages/faustwp-core/src/hooks/useAuth.tsx | Reacts to authentication changes and refreshes viewer data. |
| packages/faustwp-core/src/auth/client/accessToken.ts | Adds authentication-change listeners. |
| docs/reference/use-auth/index.md | Documents updates without page reloads. |
Review effort: Balanced
…ount switches useAuth now catches up with logins and logouts that happened while skip was true, provides a login URL when an authenticated session ends, and ignores a viewer response that started before the latest login or logout, without sharing its request.
Merged
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.

Fixes #1923
useAuthnow listens for this tab storing or clearing its access token, so it also flips tofalse(and clearsviewer) if a token refresh fails, which it didn't notice before; verified with Jest (the new test fails without the fix), not in a browser.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Assisting with tracing the cause, the fix, the tests and the docs note.