Add multi-instance support and session management in nextjs#394
Draft
kavindadimuthu wants to merge 7 commits intoasgardeo:mainfrom
Draft
Add multi-instance support and session management in nextjs#394kavindadimuthu wants to merge 7 commits intoasgardeo:mainfrom
kavindadimuthu wants to merge 7 commits intoasgardeo:mainfrom
Conversation
…session management utilities for instance handling - Step 1, 2, 3
- Step 4 - Updated `isSignedIn` to accept an optional instance ID for better session management. - Modified `signInAction`, `signOutAction`, `signUpAction`, `switchOrganization`, and `updateUserProfileAction` to include instance ID handling. - Ensured that session cookies are managed per instance to support multi-instance scenarios. - Improved error handling and logging across actions for better debugging.
- Refactor createOrganization function to improve parameter order and maintain code consistency
…ession handling - Updated getAllOrganizations, handleOAuthCallbackAction, signInAction, signUpAction, switchOrganization, and updateUserProfileAction to accept instanceId as a parameter for better session management. - Enhanced asgardeo middleware to support instanceId, ensuring consistent session handling across requests. - Improved error handling and logging in various actions to provide clearer feedback on failures.
…improved session handling
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. |
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.
Purpose
This pull request introduces support for multiple independent authentication client instances ("multiton" pattern) in the Asgardeo Next.js integration, allowing different parts of an application to use separate authentication contexts. The changes refactor the client and server provider logic, update server actions and tests to handle instance IDs, and ensure all relevant functions and actions are instance-aware.
Client instance management:
AsgardeoNextClientfrom singleton to multiton, enabling multiple client instances identified by aninstanceId. Added methods to create, destroy, and check existence of instances, and store theinstanceIdin each instance. (packages/nextjs/src/AsgardeoNextClient.ts)AsgardeoClientProvider) and server provider (AsgardeoServerProvider) components to accept and propagateinstanceId, ensuring client and server logic operate on the correct instance. (packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx,packages/nextjs/src/server/AsgardeoProvider.tsx) [1] [2]Server actions and session management:
createOrganization,getAllOrganizations,getCurrentOrganizationAction, etc.) to accept and useinstanceId, ensuring actions interact with the correct client instance and session. (packages/nextjs/src/server/actions/createOrganization.ts,packages/nextjs/src/server/actions/getAllOrganizations.ts,packages/nextjs/src/server/actions/getCurrentOrganizationAction.ts) [1] [2] [3]instanceIdwhere needed. (packages/nextjs/src/server/AsgardeoProvider.tsx,packages/nextjs/src/server/actions/getAccessToken.ts) [1] [2]OAuth callback and action binding:
instanceIdembedded in the callback state, ensuring only the correct instance processes the callback. (packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx)packages/nextjs/src/server/AsgardeoProvider.tsx)Testing:
instanceIdhandling, ensuring correctness of the new multiton logic. (packages/nextjs/src/server/actions/__tests__/createOrganization.test.ts,packages/nextjs/src/server/actions/__tests__/getAllOrganizations.test.ts) [1] [2]These changes collectively enable robust support for multiple authentication contexts within a Next.js application, improving flexibility for multi-tenant or complex authentication scenarios.
Related Issues
Related PRs
Checklist
Security checks