Skip to content

fix(core): update useAuth after logging in with useLogin - #2683

Merged
josephfusco merged 4 commits into
canaryfrom
fix/1923-use-auth-after-login
Oct 21, 2026
Merged

josephfusco merged 4 commits into
canaryfrom
fix/1923-use-auth-after-login

Conversation

@josephfusco

Copy link
Copy Markdown
Member

Fixes #1923

useAuth now listens for this tab storing or clearing its access token, so it also flips to false (and clears viewer) 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.

@josephfusco josephfusco added [Type] Bug An existing feature is broken [Area] Core Issues for the @faustwp/core package labels Oct 20, 2026
@josephfusco
josephfusco marked this pull request as ready for review October 20, 2026 16:12
@josephfusco
josephfusco requested review from a team and colinmurphy as code owners 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread packages/faustwp-core/src/hooks/useAuth.tsx Outdated
Comment thread packages/faustwp-core/src/hooks/useAuth.tsx Outdated
Comment thread packages/faustwp-core/src/hooks/useAuth.tsx Outdated
…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.
@josephfusco
josephfusco merged commit 03818f4 into canary Oct 21, 2026
16 checks passed
@josephfusco
josephfusco deleted the fix/1923-use-auth-after-login branch October 21, 2026 15:07
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Core Issues for the @faustwp/core package [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useLogin and useAuth do not work together to update isAuthenticated/viewer

2 participants