Skip to content

feat(nextjs): expose organization, isInitialized, clientId, signInOptions, switchOrganization and getDecodedIdToken in useAsgardeo() - #565

Open
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/nextjs-context-surface
Open

feat(nextjs): expose organization, isInitialized, clientId, signInOptions, switchOrganization and getDecodedIdToken in useAsgardeo()#565
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/nextjs-context-surface

Conversation

@DonOmalVindula

Copy link
Copy Markdown
Contributor

Problem

useAsgardeo() in the Next.js SDK exposed a much smaller context than the React SDK's. In particular organization was missing although the bundled teamspace-nextjs dashboard reads organization?.orgHandle (and renders nothing), isInitialized was never set (default false), and clientId, signInOptions, switchOrganization and getDecodedIdToken were absent, so code written against the React SDK's context does not port.

Fix

AsgardeoClientProvider now provides:

  • organization – the current organization from the server provider (null when unknown),
  • isInitialized: true – the server provider only renders the client provider once the client is initialized,
  • clientId and signInOptions – from the configuration,
  • switchOrganization(organization) – the server action followed by router.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 new getDecodedIdTokenAction server action.

The raw tokens stay in the HttpOnly session cookie by design, so getAccessToken, getIdToken and exchangeToken are intentionally not part of the Next.js context (the context type documents this; http.request covers authenticated calls).

Testing

  • New getDecodedIdTokenAction unit 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/nextjs patch).

🤖 Generated with Claude Code

…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>
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 3c779025-48d5-4e1c-b7bf-cb4fd3c34aa6

📥 Commits

Reviewing files that changed from the base of the PR and between 409ebae and 8709ce8.

📒 Files selected for processing (6)
  • .changeset/nextjs-context-surface.md
  • packages/nextjs/src/client/contexts/Asgardeo/AsgardeoContext.ts
  • packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx
  • packages/nextjs/src/server/AsgardeoProvider.tsx
  • packages/nextjs/src/server/actions/__tests__/getDecodedIdTokenAction.test.ts
  • packages/nextjs/src/server/actions/getDecodedIdTokenAction.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@asgardeo-github-bot

Copy link
Copy Markdown

🦋 Changeset detected

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants