feat(nextjs): expose organization, isInitialized, clientId, signInOptions, switchOrganization and getDecodedIdToken in useAsgardeo() - #565
Open
DonOmalVindula wants to merge 1 commit into
Conversation
…ions, switchOrganization and getDecodedIdToken in useAsgardeo() The Next.js context lacked several fields the React SDK's context provides; the bundled sample already read `organization` and got undefined. - organization: the current organization from the server provider. - isInitialized: true (the client provider is only rendered once the client has been initialized), clientId and signInOptions from the configuration. - switchOrganization(): the server action, followed by router.refresh() so the server components pick up the switched session. - getDecodedIdToken(): the ID token claims through a new server action; the raw tokens stay in the HttpOnly cookie (hence no getAccessToken/getIdToken/ exchangeToken in the browser). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 47 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🦋 Changeset detectedThe changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. |
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.
Problem
useAsgardeo()in the Next.js SDK exposed a much smaller context than the React SDK's. In particularorganizationwas missing although the bundledteamspace-nextjsdashboard readsorganization?.orgHandle(and renders nothing),isInitializedwas never set (defaultfalse), andclientId,signInOptions,switchOrganizationandgetDecodedIdTokenwere absent, so code written against the React SDK's context does not port.Fix
AsgardeoClientProvidernow provides:organization– the current organization from the server provider (nullwhen unknown),isInitialized: true– the server provider only renders the client provider once the client is initialized,clientIdandsignInOptions– from the configuration,switchOrganization(organization)– the server action followed byrouter.refresh(), so the server components re-read the switched session and hand down the new organization, user and organization list (the organization context uses the same function),getDecodedIdToken()– the ID token claims through a newgetDecodedIdTokenActionserver action.The raw tokens stay in the HttpOnly session cookie by design, so
getAccessToken,getIdTokenandexchangeTokenare intentionally not part of the Next.js context (the context type documents this;http.requestcovers authenticated calls).Testing
getDecodedIdTokenActionunit tests (63 tests pass),pnpm lint,tsc --noEmit. The provider changes are covered by review; there is no component test setup in this package.Changeset included (
@asgardeo/nextjspatch).🤖 Generated with Claude Code