Skip to content

fix: handle waitlist restricted error & don't clear errors always on … - #6818

Closed
eli-front wants to merge 0 commit into
clerk:mainfrom
eli-front:fix/oauth-callback-clears-errors
Closed

eli-front wants to merge 0 commit into
clerk:mainfrom
eli-front:fix/oauth-callback-clears-errors

Conversation

@eli-front

@eli-front eli-front commented Sep 19, 2025 •

Copy link
Copy Markdown

…exit to prevent early clear

Description

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:

Error Iteration Fix

Errors were previously not being parse correctly on the ERRORS.SET event causing an issue of "errors not iterable". The sign_up_restricted_waitlist error does contain a clerkError key, so it's considered a clerk api response error, but it does not have the plural "errors" in it, but a singular "error".

Error Clearing Fix

Currently, when using the clerk elements <GlobalError /> component, it does not correctly handle the state in when a user attempts to sign up when the waitlist only / invite only mode is enabled on clerk. The error gets briefly set in the form state, but the exit condition on the form machine clears the errors before they are rendered to the user.

This fix will explicitly switch on this waitlist error code and it will not do a blanket clear of the errors on exit of the start state. This prevents the form from clearing errors prematurely.

Summary by CodeRabbit

  • New Features

    • Added support for restricted waitlist signup error handling.
  • Bug Fixes

    • Improved error handling consistency across authentication flows.
    • Enhanced form error clearing during navigation transitions for improved user experience.

@changeset-bot

changeset-bot Bot commented Sep 19, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8c8873d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel

vercel Bot commented Sep 19, 2025

Copy link
Copy Markdown

@eli-front is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hello 👋

We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days.

Thanks for being a part of the Clerk community! 🙏

@clerk-cookie clerk-cookie added Stale and removed Stale labels Nov 9, 2025
@eli-front

Copy link
Copy Markdown
Author

Hello 👋

We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days.

Thanks for being a part of the Clerk community! 🙏

This is still an issue (to prevent stale)

@coderabbitai

coderabbitai Bot commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces a new error code for sign-up restricted waitlist scenarios and refactors error handling across form and routing state machines. Changes normalize error processing patterns, improve safe property access, and systematically add form error clearing before navigation transitions.

Changes

Cohort / File(s) Summary
New Error Code Constant
packages/elements/src/internals/constants/index.ts
Added SIGN_UP_RESTRICTED_WAITLIST: 'sign_up_restricted_waitlist' entry to exported ERROR_CODES object.
Form Machine Error Handling
packages/elements/src/internals/machines/form/form.machine.ts
Normalized error handling in ERRORS.SET by computing candidate from Clerk API responses or direct errors; ensured errors is always an array; safely accesses error meta properties; added explicit ERRORS.CLEAR action handler.
Router Machines
packages/elements/src/internals/machines/sign-in/router.machine.ts,
packages/elements/src/internals/machines/sign-up/router.machine.ts
Extended error mapping to handle new SIGN_UP_RESTRICTED_WAITLIST code; refactored multi-line redirectUrl string concatenations to template literals; systematically added clearFormErrors to NEXT transitions before navigation; removed exit action from Start states.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Error normalization logic in form machine: Verify that the candidate computation correctly handles both Clerk API responses and direct errors, and confirm the array-wrapping logic preserves expected error iteration behavior.
  • clearFormErrors integration across routers: Confirm that clearing form errors before each navigation does not inadvertently suppress errors that should persist across state transitions.
  • Error code extension: Ensure the new SIGN_UP_RESTRICTED_WAITLIST code is handled consistently across all affected state machines and error mapping functions.

Poem

🐰 A new error code hops into the mix,
Form errors now clear before the fix,
State machines dance with patterns refined,
Safe property access on our mind,
The warren's routing flows so bright! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: handle waitlist restricted error & don't clear errors always on …' directly addresses the main changes: handling the SIGN_UP_RESTRICTED_WAITLIST error and fixing premature error clearing on state transitions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 42f0d95 and 0906b21.

📒 Files selected for processing (4)
  • packages/elements/src/internals/constants/index.ts (1 hunks)
  • packages/elements/src/internals/machines/form/form.machine.ts (2 hunks)
  • packages/elements/src/internals/machines/sign-in/router.machine.ts (6 hunks)
  • packages/elements/src/internals/machines/sign-up/router.machine.ts (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/elements/src/internals/machines/form/form.machine.ts (1)
packages/shared/src/underscore.ts (1)
  • snakeToCamel (51-53)
packages/elements/src/internals/machines/sign-up/router.machine.ts (3)
packages/elements/src/internals/machines/sign-up/router.types.ts (3)
  • SignUpRouterContext (92-97)
  • SignUpRouterEvents (67-78)
  • SignUpRouterNextEvent (48-48)
packages/clerk-js/src/core/resources/SignUp.ts (3)
  • status (108-110)
  • status (119-126)
  • status (597-600)
packages/elements/src/internals/constants/index.ts (4)
  • ERROR_CODES (46-62)
  • ROUTING (64-68)
  • ROUTING (70-70)
  • SSO_CALLBACK_PATH_ROUTE (5-5)
packages/elements/src/internals/machines/sign-in/router.machine.ts (3)
packages/elements/src/internals/machines/sign-in/router.types.ts (3)
  • SignInRouterContext (110-116)
  • SignInRouterEvents (88-104)
  • SignInRouterNextEvent (55-55)
packages/clerk-js/src/core/clerk.ts (1)
  • status (310-312)
packages/elements/src/internals/constants/index.ts (4)
  • ERROR_CODES (46-62)
  • ROUTING (64-68)
  • ROUTING (70-70)
  • SSO_CALLBACK_PATH_ROUTE (5-5)
⏰ 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). (1)
  • GitHub Check: semgrep-cloud-platform/scan

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.

@eli-front

eli-front commented Nov 18, 2025 •

Copy link
Copy Markdown
Author

@LauraBeatris could you take a look at this? (not sure who would be in charge of elements updates)

@Zertsov
Zertsov requested a review from brkalow December 12, 2025 17:38
@eli-front eli-front closed this Dec 12, 2025
@eli-front
eli-front force-pushed the fix/oauth-callback-clears-errors branch from 0906b21 to 8c8873d Compare December 12, 2025 20:31
@eli-front

eli-front commented Dec 12, 2025 •

Copy link
Copy Markdown
Author

It looks like there were some significant merge conflicts due to restructuring of clerk elements in #7271. If anyone is having this issue with waitlist signup errors not being handled right (it's still present on @clerk/elements@latest), I've been using this patch

diff --git a/dist/chunk-2NFCNVR4.mjs b/dist/chunk-2NFCNVR4.mjs
index cc770c39d5dace71b2c68eda0da00358529aa57b..507976d7a53093849c151cbaa03e45255e8a93d1 100644
--- a/dist/chunk-2NFCNVR4.mjs
+++ b/dist/chunk-2NFCNVR4.mjs
@@ -109,7 +109,10 @@ var FormMachine = setup({
         if (isKnownError(event.error)) {
           const fields = {};
           const globalErrors = [];
-          const errors = isClerkAPIResponseError(event.error) ? (_a = event.error) == null ? void 0 : _a.errors : [event.error];
+          const candidate = isClerkAPIResponseError(event.error)
+            ? (event.error?.errors || event.error)
+            : event?.error || [];
+          const errors = Array.isArray(candidate) ? candidate : [candidate];
           for (const error of errors) {
             const name = isClerkAPIError(error) ? snakeToCamel((_b = error.meta) == null ? void 0 : _b.paramName) : null;
             if (!name || isMetamaskError(error)) {
@@ -1716,7 +1719,8 @@ var ERROR_CODES = {
   ENTERPRISE_SSO_EMAIL_ADDRESS_DOMAIN_MISMATCH: "enterprise_sso_email_address_domain_mismatch",
   ENTERPRISE_SSO_HOSTED_DOMAIN_MISMATCH: "enterprise_sso_hosted_domain_mismatch",
   SAML_EMAIL_ADDRESS_DOMAIN_MISMATCH: "saml_email_address_domain_mismatch",
-  ORGANIZATION_MEMBERSHIP_QUOTA_EXCEEDED_FOR_SSO: "organization_membership_quota_exceeded_for_sso"
+  ORGANIZATION_MEMBERSHIP_QUOTA_EXCEEDED_FOR_SSO: "organization_membership_quota_exceeded_for_sso",
+  SIGN_UP_RESTRICTED_WAITLIST: 'sign_up_restricted_waitlist',
 };
 var ROUTING = {
   path: "path",
@@ -2934,6 +2938,7 @@ var SignInRouterMachine = setup6({
         case ERROR_CODES.ENTERPRISE_SSO_HOSTED_DOMAIN_MISMATCH:
         case ERROR_CODES.SAML_EMAIL_ADDRESS_DOMAIN_MISMATCH:
         case ERROR_CODES.ORGANIZATION_MEMBERSHIP_QUOTA_EXCEEDED_FOR_SSO:
+        case ERROR_CODES.SIGN_UP_RESTRICTED_WAITLIST:
           error = new ClerkElementsError(errorOrig.code, errorOrig.longMessage || "");
           break;
         default:
@@ -3177,7 +3182,6 @@ var SignInRouterMachine = setup6({
     },
     Start: {
       tags: ["step:start"],
-      exit: "clearFormErrors",
       invoke: {
         id: "start",
         src: "startMachine",
@@ -3211,21 +3215,21 @@ var SignInRouterMachine = setup6({
         NEXT: [
           {
             guard: "isComplete",
-            actions: "setActive"
+            actions: ["setActive", "clearFormErrors"]
           },
           {
             guard: "statusNeedsFirstFactor",
-            actions: { type: "navigateInternal", params: { path: "/continue" } },
+            actions: [{ type: "navigateInternal", params: { path: "/continue" } }, "clearFormErrors"],
             target: "FirstFactor"
           },
           {
             guard: "statusNeedsSecondFactor",
-            actions: { type: "navigateInternal", params: { path: "/continue" } },
+            actions: [{ type: "navigateInternal", params: { path: "/continue" } }, "clearFormErrors"],
             target: "SecondFactor"
           },
           {
             guard: "statusNeedsNewPassword",
-            actions: { type: "navigateInternal", params: { path: "/reset-password" } },
+            actions: [{ type: "navigateInternal", params: { path: "/reset-password" } }, "clearFormErrors"],
             target: "ResetPassword"
           }
         ]

This branch was successfully deployed

1 active deployment
Production — 8c8873d9 Deployed Dec 12, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants