diff --git a/.changeset/fix-network-error-cache-fallback.md b/.changeset/fix-network-error-cache-fallback.md new file mode 100644 index 00000000000..f11efdb2ad0 --- /dev/null +++ b/.changeset/fix-network-error-cache-fallback.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Fix issue where network errors were being masked by fraud protection logic, preventing cache fallback from triggering properly. diff --git a/packages/clerk-js/src/core/fraudProtection.ts b/packages/clerk-js/src/core/fraudProtection.ts index 6051f5d8010..8dcac4aebed 100644 --- a/packages/clerk-js/src/core/fraudProtection.ts +++ b/packages/clerk-js/src/core/fraudProtection.ts @@ -1,4 +1,4 @@ -import { ClerkRuntimeError, isClerkAPIResponseError } from '@clerk/shared/error'; +import { ClerkRuntimeError, isClerkAPIResponseError, isClerkRuntimeError } from '@clerk/shared/error'; import { CaptchaChallenge } from '../utils/captcha/CaptchaChallenge'; import type { Clerk } from './resources/internal'; @@ -45,6 +45,12 @@ export class FraudProtection { throw e; } + // Network errors should bypass captcha logic and be re-thrown immediately + // so cache fallback can be triggered + if (isClerkRuntimeError(e) && e.code === 'network_error') { + throw e; + } + if (e.errors[0]?.code !== 'requires_captcha') { throw e; }