Skip to content

feat(nextjs): add Thunder V2 platform compatibility#521

Open
Kavirubc wants to merge 6 commits into
asgardeo:mainfrom
Kavirubc:feat/nextjs-thunder-v2-support
Open

feat(nextjs): add Thunder V2 platform compatibility#521
Kavirubc wants to merge 6 commits into
asgardeo:mainfrom
Kavirubc:feat/nextjs-thunder-v2-support

Conversation

@Kavirubc
Copy link
Copy Markdown

@Kavirubc Kavirubc commented May 16, 2026

Purpose

Add Thunder V2 (AsgardeoV2) platform support to the @asgardeo/nextjs SDK, enabling Next.js applications to authenticate against Thunder instances.

Key changes:

  • Platform-aware rendering: SignIn and SignUp components delegate to V2 variants (SignInV2, SignUpV2) when platform="AsgardeoV2" is configured
  • FlowMetaProvider integration: Wraps the client provider chain with FlowMetaProvider for V2 embedded authentication flows
  • PKCE auto-detection: enablePKCE is now conditionally enabled based on client type — public clients (no clientSecret) get PKCE auto-enabled, confidential clients keep it disabled
  • Platform env-var support: Added NEXT_PUBLIC_ASGARDEO_PLATFORM environment variable for convenience configuration
  • Error handling fix: handleOAuthCallbackAction now correctly extracts error messages from AsgardeoAuthException (which does not extend Error)
  • Middleware import fix: Corrected the sample app middleware import path from @asgardeo/nextjs/server to @asgardeo/nextjs/middleware

Related Issues

  • N/A

Related PRs

  • Thunder: OIDC RP-Initiated Logout and Next.js integration guide (thunder-id/thunderid)

Checklist

  • Followed the CONTRIBUTING guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided. (Add links if there are any)

Security checks

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Thunder V2 platform support with new V2 Sign-In and Sign-Up components
    • Introduced render-props pattern for custom authentication UI
    • Added FlowMeta provider for advanced configuration
    • Platform configuration now available via environment variables and provider props
  • Bug Fixes

    • PKCE now dynamically enables/disables based on client secret presence
    • Enhanced error message handling in OAuth callback processing

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

📝 Walkthrough

Walkthrough

This PR adds Thunder V2 platform compatibility to the Asgardeo JavaScript SDKs by enabling platform-aware component routing in the Next.js SDK. The platform configuration flows from environment variables through config decorators and provider layers to sign-in/sign-up components, which conditionally render V2 or legacy components based on the resolved platform. The React package now exports V2 components and FlowMeta infrastructure for consumption.

Changes

Thunder V2 Platform Support

Layer / File(s) Summary
Configuration and Provider Infrastructure
packages/nextjs/src/utils/decorateConfigWithNextEnv.ts, packages/nextjs/src/AsgardeoNextClient.ts, packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx, packages/nextjs/src/server/AsgardeoProvider.tsx
Platform setting defaults from NEXT_PUBLIC_ASGARDEO_PLATFORM environment variable and flows through provider hierarchy via new platform prop; PKCE toggle changes from hardcoded false to !clientSecret; client provider extends context to include platform and wraps component tree with FlowMetaProvider.
SignIn Component V2 Routing
packages/nextjs/src/client/components/presentation/SignIn/SignIn.tsx
SignInProps extended with optional children render-props callback and preferences field; component reads platform from context and conditionally renders SignInV2 when platform is AsgardeoV2, otherwise falls back to BaseSignIn.
SignUp Component V2 Routing
packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx
SignUpProps narrowed to explicit Pick of base props plus optional children render prop; component reads platform from context and routes between SignUpV2 and BaseSignUp based on configured platform.
Public Exports and Utilities
packages/react/src/index.ts, packages/nextjs/src/server/actions/handleOAuthCallbackAction.ts
React package barrel exports FlowMetaContext, FlowMetaProvider, useFlowMeta and V2 components SignInV2, SignUpV2 with render-props types; OAuth callback action error handler improved to defensively extract error messages from Error instances or fallback message objects.
Release and Sample Updates
.changeset/nextjs-thunder-v2-support.md, samples/teamspace-nextjs/middleware.ts
Changeset documents minor version bumps for React and Next.js SDKs with V2 feature additions; sample app middleware corrects import path from @asgardeo/nextjs/server to @asgardeo/nextjs/middleware.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • ThaminduDilshan
  • DonOmalVindula
  • brionmario

Poem

🐰 A rabbit hops through Thunder's v2 gates,
Where platforms align and components create,
With children render props held tight,
And FlowMeta flows left and right,
V2 routing shines, authentication takes flight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding Thunder V2 platform compatibility to the Next.js SDK, which aligns with the changeset's core purpose.
Description check ✅ Passed The description covers all required template sections with detailed information about purpose, changes, related work, and completed security checks, though documentation and unit tests sections are marked incomplete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx`:
- Around line 35-37: The SignUpProps type currently weakens children to any and
the JSDoc incorrectly documents onSuccess/onComplete; change the children
signature to children?: (props: SignUpRenderProps) => ReactElement (replacing
any) in the SignUpProps declaration, remove the two "as any" casts where
children is passed through (the casts currently masking the type mismatch), and
update the component JSDoc/example to remove onSuccess and onComplete (or
alternatively expose them via BaseSignUpProps if you intend them to be public)
so the docs match the actual public API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 09bf3808-6a77-452c-9b93-80b29f876569

📥 Commits

Reviewing files that changed from the base of the PR and between 22ee26d and 9559568.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • .changeset/nextjs-thunder-v2-support.md
  • packages/nextjs/src/AsgardeoNextClient.ts
  • packages/nextjs/src/client/components/presentation/SignIn/SignIn.tsx
  • packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx
  • packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx
  • packages/nextjs/src/server/AsgardeoProvider.tsx
  • packages/nextjs/src/server/actions/handleOAuthCallbackAction.ts
  • packages/nextjs/src/utils/decorateConfigWithNextEnv.ts
  • packages/react/src/index.ts
  • samples/teamspace-nextjs/middleware.ts

Comment on lines +35 to +37
export type SignUpProps = Pick<BaseSignUpProps, 'className' | 'afterSignUpUrl' | 'onError' | 'variant' | 'size'> & {
children?: (props: any) => ReactElement;
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify whether current repo callsites use callbacks now excluded by narrowed SignUpProps.
rg -nP --type=tsx -C2 '<SignUp[^>]*(onSuccess|onComplete|onInitialize|onSubmit)\s*='

# Inspect current exported SignUpProps definition.
rg -n -C3 'export type SignUpProps' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

Repository: asgardeo/javascript

Length of output: 91


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# First, locate and inspect the SignUp.tsx file
fd -t f "SignUp.tsx" packages/nextjs

# Get the file size
wc -l packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Read the specific lines mentioned in the review
echo "=== Lines 35-37 (SignUpProps definition) ==="
sed -n '35,37p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

echo "=== Lines 75-77 ==="
sed -n '75,77p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

echo "=== Lines 116-127 ==="
sed -n '116,127p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

echo "=== Lines 141-144 ==="
sed -n '141,144p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Search for SignUpRenderProps definition
echo "=== Search for SignUpRenderProps ==="
rg -n "SignUpRenderProps" packages/nextjs/src/client/components/presentation/SignUp/

# Search for BaseSignUpProps definition to see all available props
echo "=== Search for BaseSignUpProps ==="
rg -n "export.*BaseSignUpProps" packages/nextjs/src/client/components/presentation/SignUp/

Repository: asgardeo/javascript

Length of output: 1290


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for BaseSignUpProps definition - might be in node_modules or imported
echo "=== Searching for BaseSignUpProps definition in react package ==="
fd -t f "index" packages/nextjs/node_modules/@asgardeo/react/dist/ | head -5

# Let's look at the actual type exports from `@asgardeo/react`
echo "=== Checking `@asgardeo/react` exports ==="
find packages/nextjs/node_modules/@asgardeo/react -name "*.d.ts" -o -name "index.ts" | head -10

# Search for usages of <SignUp component in the codebase (excluding SignUpV2)
echo "=== Searching for <SignUp usage patterns ==="
rg -n "<SignUp\b" packages/nextjs/src --type ts -A2 | head -50

# Also check examples or tests that might use SignUp
echo "=== Checking for SignUp usage in examples/tests ==="
rg -n "SignUp" packages/nextjs/examples 2>/dev/null || echo "No examples directory or no matches"

# Check if ...rest is actually passed down and what callbacks it might contain
echo "=== Full context around line 75-77 where rest is extracted ==="
sed -n '70,95p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

Repository: asgardeo/javascript

Length of output: 285


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for actual <SignUp usage in the codebase
echo "=== Searching for <SignUp usage in source code ==="
rg -n "<SignUp\b" packages/nextjs/src -A3 | head -80

# Get the full function signature to see what rest contains
echo "=== Full function context around parameter destructuring ==="
sed -n '70,100p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Check if there's documentation or types file
echo "=== Looking for type definitions in the file ==="
sed -n '1,40p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Search for any usage of the excluded callbacks in the whole packages/nextjs directory
echo "=== Searching for onSuccess, onComplete, onInitialize, onSubmit with SignUp ==="
rg -n "(onSuccess|onComplete|onInitialize|onSubmit)" packages/nextjs/src --type ts | grep -i signup || echo "No matches found"

Repository: asgardeo/javascript

Length of output: 3247


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for imports of SignUp from packages/nextjs
echo "=== Searching for imports of SignUp component ==="
rg -n "from.*SignUp" packages/nextjs/src --type ts | grep -v "BaseSignUp\|SignUpV2\|SignUpRenderProps" | head -20

# Search in example files
echo "=== Checking example/demo files ==="
find packages/nextjs -type f \( -name "*.tsx" -o -name "*.ts" \) -path "*/example*" -o -path "*/demo*" | head -20

# Check where SignUp is exported from
echo "=== Checking barrel exports ==="
rg -n "SignUp" packages/nextjs/src/client/components/index.ts || echo "Not found"
rg -n "SignUp" packages/nextjs/src/index.ts || echo "Not found"

# Get the full context where onInitialize and onSubmit are used
echo "=== Context around lines 134-135 where callbacks are passed ==="
sed -n '87,140p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Look for handleOnSubmit definition
echo "=== Looking for handleOnSubmit definition ==="
rg -n "handleOnSubmit" packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx -B5 -A5

Repository: asgardeo/javascript

Length of output: 3027


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Get the full JSDoc section for the SignUp component
echo "=== Full JSDoc/comments for SignUp component ==="
sed -n '39,70p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Search for tests related to SignUp
echo "=== Searching for SignUp tests ==="
find packages/nextjs -type f \( -name "*.test.tsx" -o -name "*.test.ts" -o -name "*.spec.tsx" -o -name "*.spec.ts" \) | xargs grep -l "SignUp" 2>/dev/null || echo "No tests found mentioning SignUp"

# Check what callbacks BaseSignUp actually accepts by looking at imports/usage
echo "=== Full usage context of BaseSignUp ==="
sed -n '130,148p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

# Check rest parameter - what's actually being passed
echo "=== Complete function parameters ==="
sed -n '73,78p' packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx

Repository: asgardeo/javascript

Length of output: 1690


Fix JSDoc and restore type safety for children prop.

The JSDoc example documents onSuccess and onComplete callbacks (lines 49-57), but these are not exposed in SignUpProps nor implemented in the component—they're only shown in misleading documentation. The narrowed Pick<BaseSignUpProps, ...> appears intentional, as the component handles initialization and submission internally via hardcoded callbacks passed to BaseSignUp.

However, the any type for the children prop (lines 36, 126, 143) unnecessarily drops type safety. Use SignUpRenderProps instead:

Proposed fix
 export type SignUpProps = Pick<BaseSignUpProps, 'className' | 'afterSignUpUrl' | 'onError' | 'variant' | 'size'> & {
-  children?: (props: any) => ReactElement;
+  children?: (props: SignUpRenderProps) => ReactElement;
 };

Then remove the as any casts at lines 126 and 143:

-        {children as any}
+        {children}

The JSDoc example should also be corrected to remove onSuccess and onComplete callbacks, or those callbacks should be properly implemented and exposed if they are intended to be part of the public API.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export type SignUpProps = Pick<BaseSignUpProps, 'className' | 'afterSignUpUrl' | 'onError' | 'variant' | 'size'> & {
children?: (props: any) => ReactElement;
};
export type SignUpProps = Pick<BaseSignUpProps, 'className' | 'afterSignUpUrl' | 'onError' | 'variant' | 'size'> & {
children?: (props: SignUpRenderProps) => ReactElement;
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/nextjs/src/client/components/presentation/SignUp/SignUp.tsx` around
lines 35 - 37, The SignUpProps type currently weakens children to any and the
JSDoc incorrectly documents onSuccess/onComplete; change the children signature
to children?: (props: SignUpRenderProps) => ReactElement (replacing any) in the
SignUpProps declaration, remove the two "as any" casts where children is passed
through (the casts currently masking the type mismatch), and update the
component JSDoc/example to remove onSuccess and onComplete (or alternatively
expose them via BaseSignUpProps if you intend them to be public) so the docs
match the actual public API.

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.

1 participant