fix(nextjs): call the /o APIs for organization sessions on the server - #553
Open
DonOmalVindula wants to merge 1 commit into
Open
fix(nextjs): call the /o APIs for organization sessions on the server#553DonOmalVindula wants to merge 1 commit into
DonOmalVindula wants to merge 1 commit into
Conversation
AsgardeoProvider computed the `${baseUrl}/o` base URL for sessions that
belong to an organization, but only handed it to the client-side context.
The server actions behind getUser/getUserProfile/updateUserProfile and
createOrganization/getOrganization kept using the root base URL from the
client configuration, so B2B and organization-switched sessions called the
root SCIM2 and organization endpoints with an organization-scoped token and
were rejected; the profile then fell back to the ID token claims.
Resolve the base URL per call from the session cookie (organizationId is set
from the `user_org` claim), mirroring the React SDK.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 48 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 (3)
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
For a session that belongs to an organization (a B2B sign-in or an organization switch, i.e. the ID token carries a
user_orgclaim), the SCIM2 and organization APIs must be called under/o. The React SDK does this inupdateSession()(${baseUrl}/owhenuser_orgis present).In the Next.js SDK,
AsgardeoServerProvidercomputes the same/obase URL, but only passes it to the client-side context. Every server action goes throughAsgardeoNextClient, whosegetUser,getUserProfile,updateUserProfile,createOrganizationandgetOrganizationread the rootbaseUrlfrom the client configuration. So for organization sessions the SCIM2Me/Schemascalls, profile updates, and organization creation/lookup hit the root endpoints with an organization-scoped token: the profile silently falls back to the ID token claims (editing disabled) and the organization operations fail.Fix
AsgardeoNextClient.resolveBaseUrl()returns${baseUrl}/owhen the session cookie carries anorganizationId(set from theuser_orgclaim at sign-in / switch / refresh), otherwise the configured base URL. It does not append/otwice when the configured base URL already targets an organization.getMyOrganizations/getAllOrganizationskeep the root base URL, which is what the React SDK's client does for those two calls.Testing
getScim2Me,getSchemas,updateMeProfile,createOrganizationandgetOrganizationfor root sessions, organization sessions, an already/obase URL, and no session cookie (66 tests pass).pnpm lintandtsc --noEmitfor@asgardeo/nextjs.Changeset included (
@asgardeo/nextjspatch).🤖 Generated with Claude Code