docs: document useSyncExternalStore pattern for reactive auth state#259
Merged
docs: document useSyncExternalStore pattern for reactive auth state#259
Conversation
Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/c69b4006-c21b-4061-b105-aa19281aa97b Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/c69b4006-c21b-4061-b105-aa19281aa97b Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add usage example for useSyncExternalStore pattern in README
docs: document useSyncExternalStore pattern for reactive auth state
Apr 4, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates the @forward-software/react-auth package documentation to describe the intended React useSyncExternalStore integration pattern for consuming reactive auth state from EnhancedAuthClient.
Changes:
- Added a “Reactive auth state with
useSyncExternalStore” section tolib/README.md. - Included a TSX example showing initialization/auth guards and token usage via
subscribe/getSnapshot. - Documented the snapshot fields and described what operations trigger re-renders.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@copilot look into the review comments and apply suggestions that look appropriate/correct |
…curacy Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/bf046831-969a-4a72-bd88-914b50836046 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
Contributor
Author
Applied all three suggestions in commit
|
panz3r
approved these changes
Apr 4, 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.
Affected Package(s)
@forward-software/react-auth(lib)@forward-software/react-auth-google(packages/google-signin)Related Issue(s)
Closes #253
Motivation
EnhancedAuthClient.subscribeandgetSnapshotare purpose-built foruseSyncExternalStore, but this was never documented. Without it, consumers are likely to reach for fragile loading-state workarounds that miss auth state changes in multi-component layouts.Description of Changes
useSyncExternalStore" section tolib/README.mdas a#####subsection correctly nested under#### EnhancedAuthClient, directly after the methods list:subscribe/getSnapshotas the recommended pattern for reading auth state in componentsisInitialized,isAuthenticated,tokens) accurately:tokensis an empty object{}when no tokens are available (e.g. before login or after logout), nevernulllogin(),refresh(),logout(), and initialization operations update the auth state and trigger re-renders (matching the actual implementation wheresetStateis only called on the success path)Breaking Changes
None
How to Test
Vitest) and build steps pass successfully on this PR.pnpm installto install dependencies.pnpm --filter @forward-software/react-auth testto run tests for the affected package.pnpm --filter @forward-software/react-auth buildto verify the build succeeds.pnpm --filter @forward-software/react-auth lintto check for linting errors.Checklist
Notes for Reviewers
Docs-only change — no source files modified, all 46 existing tests pass. The example uses
authClient(the exact key returned bycreateAuth()) to stay consistent with the established API naming.