feat(clerk-js,shared,ui): Add Protect SDK challenge support during sign-up and sign-in#8329
Draft
zourzouvillys wants to merge 1 commit intomainfrom
Draft
feat(clerk-js,shared,ui): Add Protect SDK challenge support during sign-up and sign-in#8329zourzouvillys wants to merge 1 commit intomainfrom
zourzouvillys wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 8529397 The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
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 |
…gn-up and sign-in Adds client-side support for mid-flow SDK challenges issued by the antifraud service during sign-up and sign-in. - New `protectCheck` field and `submitProtectCheck()` method on SignUp and SignIn resources - New `'needs_protect_check'` value on the SignInStatus union - New `protect-check` route on the prebuilt `<SignIn />` and `<SignUp />` components that loads the challenge SDK, submits the proof token, and resumes the flow
24c3383 to
8529397
Compare
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.
Summary
Adds client-side support for Clerk Protect mid-flow SDK challenges during both sign-up and sign-in. When the antifraud service issues a challenge, the SDK now exposes the challenge data, surfaces a UI to load and execute the challenge script, and resolves the gate via a dedicated endpoint.
protectCheckfield andsubmitProtectCheck()method to bothSignUpandSignInresources'needs_protect_check'value to theSignInStatusunionprotect-checkroute to the prebuilt<SignIn />and<SignUp />components that loads the challenge SDK, submits the proof token, and resumes the original flowBackground
Previously, anti-fraud blocks could only happen at sign-in/sign-up create time. The new mechanism allows the service to gate at any step (e.g., between identifier and first-factor, before sending an SMS code, before finalizing). When gated, the response carries:
{ "protect_check": { "status": "pending", "token": "<challenge token>", "sdk_url": "https://.../sdk.js", "expires_at": 1700000000000, "ui_hints": { ... } } }The client loads the SDK at
sdk_url, executes the challenge withtoken, and submits the resulting proof token toPATCH /v1/client/sign_{ins,ups}/{id}/protect_check. The response either clears the gate, issues a chained challenge, or completes the flow.A previous attempt at SDK support (#7894) targeted an earlier server API and was closed. This PR targets the current backend contract.
Implementation
Type additions (
@clerk/shared)ProtectCheckJSON/ProtectCheckResourcewith fields{ status: 'pending', token, sdkUrl, expiresAt?, uiHints? }protect_check?: ProtectCheckJSON | nullonSignUpJSONandSignInJSON'protect_check'added toSignUpField(so it appears inmissing_fieldsfor sign-up)'needs_protect_check'added toSignInStatussubmitProtectCheckmethod onSignUpResource,SignUpFutureResource,SignInResource,SignInFutureResourceCore resources (
@clerk/clerk-js)SignUpandSignInnow exposeprotectCheckandsubmitProtectCheck({ proofToken })(PATCH .../protect_check)fromJSON/__internal_toSnapshotround-trip the fieldSignUpFuture/SignInFuturemirror the API for the experimental hooksFlow orchestration
completeSignUpFlowadds a newprotectCheckPathparameter and routes to it whenprotectCheckis present (or'protect_check'is inmissing_fields)clerk._handleRedirectCallback(OAuth/SAML callback path) checks for the gate after the callback resolvesisSignInProtectGated()helper and route toprotect-checkPrebuilt UI (
@clerk/ui)protect-checkroute on both<SignUp />and<SignIn />SignUpProtectCheck/SignInProtectCheckcard components that:import()the challenge SDK fromsdkUrl<div>and the resourceprotect_check_already_resolvedas a soft success and continue the flowProtectCheckElement(mirrorsCaptchaElement) — DOM container with aMutationObserverso external scripts can resize the host elementBackwards compatibility
protect_checkfield on responses. Older clients hitting newer servers continue to work — the server emits'needs_protect_check'only when a feature gate matches, falling back to the underlying status otherwise.'needs_protect_check'addition toSignInStatusis type-additive but will surface as a new exhaustive-switch branch for downstream consumers using strict TypeScript.Risks
signIn.statusneed to handle'needs_protect_check'(or theprotectCheckfield) themselves. Without handling, the UI will appear stuck at the previous step. The new fields are documented on theSignInResourceinterface.(container, resource) => Promise<string>. If a different SDK is loaded with a different signature, the challenge will fail and the user will see an error in the protect-check card./* webpackIgnore: true */so bundlers don't try to inline. The URL comes from the server response; it is always HTTPS but applications with strict CSP may need to allow the relevant script origin._handleRedirectCallbackbefore the existing transfer logic. Behavioral parity verified for all fourres.statuscases of the existing transfer path.Test plan
SignUp.test.ts— 4 new tests for serialization, optional fields, snapshot round-trip,submitProtectCheckAPI callSignIn.test.ts— 5 new tests for the same surfacecompleteSignUpFlow.test.ts— 4 new tests for routing behavior (missing-field signal, field signal, priority over enterprise_sso, fallback when no path provided)@clerk/clerk-js,@clerk/shared,@clerk/uiall build cleanOut of scope (follow-ups)
SignInProtectCheck/SignUpProtectCheck(would need to mock dynamicimport())@clerk/backendresource model updates (backend SDK doesn't drive end-user flows)