fix(shared): Handle missing sessionClaims and orgRole in resolveAuthState#8118
Draft
jacekradko wants to merge 1 commit intomainfrom
Draft
fix(shared): Handle missing sessionClaims and orgRole in resolveAuthState#8118jacekradko wants to merge 1 commit intomainfrom
jacekradko wants to merge 1 commit intomainfrom
Conversation
…tate resolveAuthState had gaps in its condition branches that caused it to return undefined, triggering "Invalid state" errors. This was exposed by #8101 when touch responses came back without last_active_token. Two fixes: - When sessionId/userId exist but sessionClaims is missing (e.g. during client hydration before token fetch), return loading state instead of throwing - When orgId exists but orgRole is missing, fall through to signed-in without org state instead of throwing
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Member
|
@jacekradko I don't think this is a change we want to make, the error we encountered was good and revealed the underlying issue. WDYT? |
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.
Summary
resolveAuthStateto handle two edge cases that previously returnedundefined, causing "Invalid state" errorssessionId/userIdexist butsessionClaimsis missing (e.g. during client hydration before a token is fetched), returns a loading state (isLoaded: false) instead of throwingorgIdexists butorgRoleis missing (e.g. membership not yet resolved), falls through to signed-in-without-org state instead of throwingContext
This was exposed by #8101 when touch responses came back without
last_active_token, causingsessionClaimsto beundefined. While #8101 has been reverted, the underlying gap inresolveAuthStateremains — any scenario wherelastActiveTokenis null (network errors, race conditions, backend changes) can trigger the same crash.Test plan
npx vitest run packages/react/src/hooks/__tests__/useAuth.test.tsx— 30/30 passingnpx vitest run packages/shared/src/__tests__/authorization.spec.ts— 4/4 passingnpx turbo run build --filter=@clerk/shared --filter=@clerk/react --filter=@clerk/nextjs— builds clean