feat(js,shared,ui): Add protect check as missing requirement with prepare/attempt pattern#7894
feat(js,shared,ui): Add protect check as missing requirement with prepare/attempt pattern#7894zourzouvillys wants to merge 2 commits intomainfrom
Conversation
…pare/attempt pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThis pull request introduces a new Protect Check flow to the Clerk sign-up authentication process. The changes add a 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Summary
Implements protect check as a missing requirement field (
'protect_check'inmissingFields) handled via the prepare/attempt pattern with dedicated FAPI actions (prepare_protect_check/attempt_protect_check), replacing the previous auto-execution model.This gives the backend full control over when to require a protect check — it can dynamically add
protect_checktomissing_fieldsbased on rules and risk signals at any point in the sign-up flow.How it works
'protect_check'tomissing_fieldscompleteSignUpFlowdetects'protect_check'inmissingFields(checked first, before everything else includingenterprise_sso)signUp.runProtectCheck()which internally:POST prepare_protect_check→ backend returnsverifications.protect_check: { url: '...' }import(url), execute script in DOM container → script returns resultPOST attempt_protect_checkwith result → backend clearsprotect_checkfrommissing_fieldscompleteSignUpFlowre-evaluates recursively and continues (email verification, phone verification, etc.)Key design decisions
create(),update(),prepareVerification(),attemptVerification(), and allSignUpFuturemethods no longer auto-execute protect checks. The check only runs when explicitly called viarunProtectCheck()or whencompleteSignUpFlowdetects it inmissingFields.protect_checkis checked beforeenterprise_ssoand all other missing requirements incompleteSignUpFlow, since it can appear at any point in the flow.runProtectCheck()completes,completeSignUpFlowcalls itself again to re-evaluate the updated sign-up state and continue with the next requirement.API changes
New type:
ProtectCheckField'protect_check'can now appear inmissingFields,requiredFields, andoptionalFieldsarrays onSignUpResource/SignUpFutureResource.New method:
SignUpResource.runProtectCheck()Runs the full prepare → execute → attempt protect check flow. Called by
completeSignUpFlowwhen'protect_check'is inmissingFields, or can be called directly in custom flows.New method:
SignUpFutureVerifications.runProtectCheck()Same flow, wrapped in
runAsyncResourceTaskfor the future API pattern (returns{ error }instead of throwing).New property:
SignUpFutureVerifications.protectCheckExposes the protect check URL from the underlying resource verifications.
New JSON field:
SignUpVerificationsJSON.protect_checkFAPI version bump
SUPPORTED_FAPI_VERSIONupdated from'2025-11-10'to'2026-03-01'to support the newprepare_protect_checkandattempt_protect_checkactions.Versioning impact
This is a minor version change for:
@clerk/shared: New types (ProtectCheckField,runProtectCheckon interfaces), new constant (PROTECT_CHECK_CONTAINER_ID), updatedcompleteSignUpFlowbehavior, FAPI version bump@clerk/clerk-js: NewrunProtectCheck()method onSignUpclass, newexecuteProtectCheckutility, updatedSignUpVerificationsclass, updatedSignUpFutureVerificationsclass@clerk/ui: NewProtectCheckElementcomponent rendered in sign-up formsBreaking change considerations
completeSignUpFlownow handlesprotect_checkautomatically. Existing code that callscompleteSignUpFlowwill transparently handle protect checks without changes.SignUpFieldtype union is widened to include'protect_check'. Code that exhaustively matches onSignUpFieldvalues will need to handle the new variant.create()/update()/ verification methods, it must now either usecompleteSignUpFlow(which handles it automatically) or callrunProtectCheck()explicitly.Files changed
packages/shared/src/types/signUpCommon.tsProtectCheckFieldtype, updateSignUpFieldunion, addprotectChecktoSignUpVerificationsResourcepackages/shared/src/types/signUp.tsrunProtectCheckmethod toSignUpResourcepackages/shared/src/types/signUpFuture.tsprotectCheckgetter andrunProtectCheckmethod toSignUpFutureVerificationspackages/shared/src/types/json.tsprotect_checktoSignUpVerificationsJSONpackages/shared/src/internal/clerk-js/constants.tsSUPPORTED_FAPI_VERSIONto2026-03-01, addPROTECT_CHECK_CONTAINER_IDpackages/shared/src/internal/clerk-js/completeSignUpFlow.tsprotect_checkas first check inmissing_requirementsbranchpackages/clerk-js/src/core/resources/Verification.tsprotectCheckfield toSignUpVerificationsclass (deserialization + snapshot)packages/clerk-js/src/core/resources/SignUp.tsrunProtectCheck()toSignUp, add_runProtectChecktoSignUpFuture, wire throughSignUpFutureVerifications, add container helperspackages/clerk-js/src/utils/protectCheck/executeProtectCheckutility (dynamic import + script execution)packages/ui/src/elements/ProtectCheckElement.tsxpackages/ui/src/components/SignUp/SignUpForm.tsx<ProtectCheckElement />in sign-up formpackages/ui/src/components/SignUp/SignUpStart.tsx<ProtectCheckElement />in sign-up startTest plan
@clerk/sharedbuilds cleanly (turbo build --filter=@clerk/shared)@clerk/clerk-jsbuilds cleanly with type declarations (turbo build --filter=@clerk/clerk-js)SignUp.test.ts— 53 tests pass: serialization, create, password, sso, web3, ticket, finalize, reset, protect check (runProtectCheck prepare→execute→attempt flow, container cleanup, error handling, no auto-execution from create/password/sso)protectCheck.test.ts— 5 tests pass: error code classification, script load behavior, barrel exportprotect_checkinmissing_fieldscompleteSignUpFlowrecursion works end-to-end with real FAPI responses🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
runProtectCheck()method to enable a new protect check step in the sign-up flowTests
Chores