Skip to content

feat(clerk-js): Trigger a new request to submit the captcha token #6076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

anagstef
Copy link
Member

@anagstef anagstef commented Jun 6, 2025

Description

This PR introduces support for a two-request sign up creation. This only happens when the bot-protection is enabled, so the client fires a POST on /sign_ups without a captcha token, and immediately a PATCH on /sign_ups/sua_XXX with the captcha token.

After the first API call, the Sign Up Attempt will include the challenge string inside the missing_fields array.

This is part of a bigger effort to decouple the initial sign up attempt creation from the submission of a challenge (like CAPTCHA token, or a device attestation proof).

It also fixes a rare bug on sign ups, where a captcha challenge was triggered, while we only wanted to clear the error message by triggering a new sign up attempt. That's why an option named skipChallenge is also introduced.

The new functionality is enabled only when the display_config.two_step_sign_up_create_enabled boolean feature flag is true. This way we will rollout the new functionality gradually, and eventually totally remove the legacy code.

Our backend will still support both ways of submitting a CAPTCHA to provide backwards compatibility.

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

  • New Features

    • Introduced a feature-flagged two-step sign-up creation flow, allowing for enhanced control over the sign-up process.
    • Added support for optionally skipping captcha challenges during sign-up.
  • Bug Fixes

    • Improved handling of OAuth errors during sign-up, ensuring more reliable reset behavior.
  • Refactor

    • Streamlined and clarified captcha challenge handling for a more modular and maintainable sign-up experience.

Copy link

changeset-bot bot commented Jun 6, 2025

🦋 Changeset detected

Latest commit: fe50d7d

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

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Patch
@clerk/types Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys 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

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

Copy link

vercel bot commented Jun 6, 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 Jun 16, 2025 2:37pm

@anagstef
Copy link
Member Author

anagstef commented Jun 6, 2025

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.1.0-snapshot.v20250606145508
@clerk/astro 2.9.0-snapshot.v20250606145508
@clerk/backend 2.0.0-snapshot.v20250606145508
@clerk/chrome-extension 2.4.11-snapshot.v20250606145508
@clerk/clerk-js 5.68.0-snapshot.v20250606145508
@clerk/elements 0.23.32-snapshot.v20250606145508
@clerk/clerk-expo 2.13.0-snapshot.v20250606145508
@clerk/expo-passkeys 0.3.9-snapshot.v20250606145508
@clerk/express 1.6.0-snapshot.v20250606145508
@clerk/fastify 2.3.0-snapshot.v20250606145508
@clerk/localizations 3.16.4-snapshot.v20250606145508
@clerk/nextjs 6.21.0-snapshot.v20250606145508
@clerk/nuxt 1.7.0-snapshot.v20250606145508
@clerk/clerk-react 5.31.9-snapshot.v20250606145508
@clerk/react-router 1.5.0-snapshot.v20250606145508
@clerk/remix 4.8.0-snapshot.v20250606145508
@clerk/shared 3.9.6-snapshot.v20250606145508
@clerk/tanstack-react-start 0.16.0-snapshot.v20250606145508
@clerk/testing 1.8.0-snapshot.v20250606145508
@clerk/themes 2.2.49-snapshot.v20250606145508
@clerk/types 4.60.0-snapshot.v20250606145508
@clerk/vue 1.8.7-snapshot.v20250606145508

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

📝 Walkthrough

Walkthrough

This change introduces a feature-flagged two-step sign-up creation flow in the sign-up process for the @clerk/clerk-js and @clerk/types packages. A new boolean property, twoStepSignUpCreateEnabled, is added to configuration types and classes to control this flow. The SignUp class’s create method is refactored to select between legacy and two-step sign-up flows based on this flag, with modularized handling of captcha challenges. The method signature for create in both implementation and types is updated to accept an optional options parameter, allowing the caller to skip captcha challenges. Related utility and UI code are updated to support these changes and to clarify error handling and feature flag usage.


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

@anagstef
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/chrome-extension 2.4.13-snapshot.v20250616134309
@clerk/clerk-js 5.69.1-snapshot.v20250616134309
@clerk/clerk-expo 2.13.2-snapshot.v20250616134309

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@anagstef anagstef marked this pull request as ready for review June 16, 2025 14:36
@anagstef anagstef requested review from aeliox, wobsoriano and a team as code owners June 16, 2025 14:36
@anagstef anagstef self-assigned this Jun 16, 2025
@anagstef anagstef requested a review from nikosdouvlis June 16, 2025 14:36
Copy link
Contributor

@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

🧹 Nitpick comments (5)
.changeset/dark-moons-sort.md (1)

1-6: Expand the changeset description for clarity

The summary is accurate but very terse. Mentioning the new skipChallenge option and the two_step_sign_up_create_enabled flag would help downstream readers understand why a patch is published and what behaviour changes to expect.

packages/types/src/signUp.ts (1)

74-75: Document the new options parameter

SignUpResource.create now accepts a second options argument but the interface lacks a short comment explaining the intent of skipChallenge. Adding a one-liner here (and in generated docs) prevents confusion for SDK consumers.

Also applies to: 202-205

packages/clerk-js/src/utils/captcha/CaptchaChallenge.ts (1)

64-66: Comment & code out of sync

The inline comment says “if captcha action is signup, we return undefined”, yet the guard actually checks for 'verify'.
This mismatch can confuse future readers and reviewers.

-// if captcha action is signup, we return undefined, because it means that the bot protection is disabled
+// When bot protection is disabled we return undefined for non-'verify' actions,
+// allowing sign-up flows to proceed without a captcha.
packages/clerk-js/src/core/resources/SignUp.ts (2)

87-95: skipChallenge silently ignored when two-step flow is off

If the feature flag twoStepSignUpCreateEnabled is false, callers can still pass options.skipChallenge, but the value is dropped when falling back to legacyCreate.
Either document that skipChallenge is only honoured in the two-step flow, or plumb the option through for consistency.


116-138: Lost return value from the initial POST

await this._basePost(...) is awaited but its returned SignUpResource is discarded.
Even though _basePost mutates this, capturing the promise result would:

  1. Make side-effects explicit.
  2. Protect against future refactors where _basePost stops mutating in place.
-    await this._basePost({ ... });
+    const created = await this._basePost({ ... });

Then continue operating on created (or assign back to this) to avoid accidental behavioural drift.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6e9bde8 and fe50d7d.

📒 Files selected for processing (7)
  • .changeset/dark-moons-sort.md (1 hunks)
  • packages/clerk-js/src/core/resources/DisplayConfig.ts (3 hunks)
  • packages/clerk-js/src/core/resources/SignUp.ts (5 hunks)
  • packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx (1 hunks)
  • packages/clerk-js/src/utils/captcha/CaptchaChallenge.ts (1 hunks)
  • packages/types/src/displayConfig.ts (2 hunks)
  • packages/types/src/signUp.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/clerk-js/src/core/resources/DisplayConfig.ts (1)

29-30: 👍 New feature flag is wired end-to-end

Property declaration, JSON deserialization and snapshot serialization are all covered. No issues spotted.

Also applies to: 84-87, 138-139

packages/types/src/displayConfig.ts (1)

27-28: LGTM – types stay in sync with runtime flag

The additional property is optional in both JSON & resource interfaces, matching the runtime default of false.

Also applies to: 73-74

Comment on lines +218 to 220
// This will be handled by the backend (FAPI) in the future.
void (await signUp.create({}, { skipChallenge: true }));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant void (await …) wrapper

Inside an async function you can simply await the promise. The current form is harder to read and offers no benefit.

-        void (await signUp.create({}, { skipChallenge: true }));
+        await signUp.create({}, { skipChallenge: true });

If the result should be ignored but failures tolerated, consider wrapping in try/catch instead of swallowing silently.

🤖 Prompt for AI Agents
In packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx around lines 218
to 220, remove the redundant 'void (await ...)' wrapper and simply use 'await'
to handle the promise. If the intention is to ignore the result but still handle
potential errors, wrap the await call in a try/catch block instead of silently
swallowing any failures.

body: normalizeUnsafeMetadata(params),
});

if (!this.shouldBypassCaptchaForAttempt(params) && !options?.skipChallenge) {
Copy link
Member

Choose a reason for hiding this comment

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

should whether challenge is a missing field factor into this check?

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.

3 participants