Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Jul 29, 2025

Description

Context

After-auth flows always send the redirect_url as redirect_url_complete in order to execute handleRedirectCallback so that the SDK can control on navigating back to the pending tasks.

We weren't dealing with the following cases:`

  • The navigation to tasks was only included within SSOCallback and didn't cover custom flows that execute handleRedirectCallback directly
  • If the session is active, then handleRedirectCallback should redirect to the redirect_url_complete from the initial flow
  • For transfer flows, on setActive, it wasn't navigating to tasks.

Proposed fixes

  • Moves task navigation to handleRedirectCallback
  • Persist redirect_url_complete as ?redirect_url param

Flows

Refer to the navigations below (I haven't implemented a custom spinner component for handleRedirectCallback

With active session and __internal_hasAfterAfterFlows:

CleanShot.2025-07-29.at.19.01.40.mp4

With pending session + transfer flow:

CleanShot.2025-07-29.at.19.24.34.mp4

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of single sign-on (SSO) callback flows, ensuring smoother navigation after authentication, especially when custom post-authentication tasks are present.
  • Tests

    • Added new test cases to verify correct redirection behavior for pending and completed session tasks after SSO authentication.
  • Documentation

    • Updated session-related documentation to clarify that sessions may be pending, not only active.

@LauraBeatris LauraBeatris self-assigned this Jul 29, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2025

🦋 Changeset detected

Latest commit: 613f916

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

This PR includes changesets to release 22 packages
Name Type
@clerk/types Patch
@clerk/clerk-js Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch
@clerk/chrome-extension Patch

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

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2025 6:58pm

@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch from ccbd1c9 to 81f7d47 Compare July 29, 2025 19:55
@LauraBeatris LauraBeatris changed the title fix(clerk-js): Fix handleRedirectCallback for after-auth fix(clerk-js): Fix SSO callback for after-auth custom flows Jul 29, 2025
@LauraBeatris LauraBeatris marked this pull request as ready for review July 29, 2025 22:25
@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch from 400b738 to e958769 Compare July 29, 2025 22:25
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

📝 Walkthrough

Walkthrough

This change set updates the single sign-on (SSO) callback handling logic in the @clerk/clerk-js package to improve support for after-authentication custom flows. The internal control flow of the _handleRedirectCallback method is modified to explicitly check for and navigate to pending session tasks after authentication. Associated logic is updated in the SignIn resource to construct redirect URLs with additional query parameters when after-auth flows are active. The UI component for SSO callback (SSOCallbackCard) is simplified by removing unused internal navigation logic. New tests are added to verify the redirect behavior for pending and resolved session tasks. A minor documentation comment update is also included.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Complexity label: Moderate
This assessment is based on the introduction of new control flow logic in the core authentication handling, updates to URL construction, removal of now-unnecessary logic in the UI, and the addition of targeted tests to verify the new behavior. The changes are focused but touch several core areas, requiring careful review for correctness and regression risks.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5af7c9d and 613f916.

📒 Files selected for processing (7)
  • .changeset/metal-geese-double.md (1 hunks)
  • .changeset/yummy-ghosts-share.md (1 hunks)
  • packages/clerk-js/src/core/__tests__/clerk.test.ts (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (5 hunks)
  • packages/clerk-js/src/core/resources/SignIn.ts (2 hunks)
  • packages/clerk-js/src/ui/common/SSOCallback.tsx (1 hunks)
  • packages/types/src/hooks.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • .changeset/yummy-ghosts-share.md
  • packages/types/src/hooks.ts
  • packages/clerk-js/src/core/resources/SignIn.ts
  • packages/clerk-js/src/ui/common/SSOCallback.tsx
  • .changeset/metal-geese-double.md
  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/tests/clerk.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 29, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6430

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6430

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6430

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6430

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6430

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6430

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6430

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6430

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6430

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6430

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6430

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6430

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6430

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6430

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6430

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6430

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6430

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6430

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6430

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6430

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6430

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6430

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6430

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6430

commit: 613f916

Comment on lines 2371 to 2379
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.#instanceType!,

this.#instanceType,
Copy link
Member Author

Choose a reason for hiding this comment

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

I have to check why my linter is making those changes on editor save... it ends up leading to a lot of build errors.

@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch 2 times, most recently from 0719d8a to cc20781 Compare July 30, 2025 14:51
Comment on lines 1956 to 1961
return this.setActive({
await this.setActive({
session: su.sessionId,
redirectUrl: redirectUrls.getAfterSignUpUrl(),
});
return this.__internal_navigateToTaskIfAvailable({ redirectUrlComplete: redirectUrls.getAfterSignUpUrl() });
Copy link
Member Author

Choose a reason for hiding this comment

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

To be clear, this doesn't impact custom flows, and developers shouldn't have to do it.

On their custom pages, Clerk.handleRedirectCallback will always navigate to the pending task route.

@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch from 8c9e577 to a899642 Compare July 30, 2025 18:35
@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch 2 times, most recently from bb88da7 to 5af7c9d Compare July 30, 2025 18:38
`handleRedirectCallback` calls `setActive` with `redirectUrl` - this gets used to navigate to once the session transitions to `active` status.

For custom flows, we don't recommend using `redirectUrl`, neither mention in our docs. This commit avoids passing `redirectUrlComplete` to `navigateToTask` to prevent race conditions on the navigation if the session is `active`.
@LauraBeatris LauraBeatris force-pushed the laura/fix-sso-callback-with-after-auth branch from 5af7c9d to 613f916 Compare July 30, 2025 18:57
@LauraBeatris LauraBeatris merged commit e8d816a into main Jul 30, 2025
36 checks passed
@LauraBeatris LauraBeatris deleted the laura/fix-sso-callback-with-after-auth branch July 30, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants