diff --git a/.changeset/fluffy-tools-live.md b/.changeset/fluffy-tools-live.md new file mode 100644 index 00000000000..ba3523370d4 --- /dev/null +++ b/.changeset/fluffy-tools-live.md @@ -0,0 +1,7 @@ +--- +'@clerk/backend': minor +'@clerk/nextjs': minor +'@clerk/shared': minor +--- + +Rename `reverificationMismatch` to `reverificationError`. diff --git a/integration/templates/next-app-router/src/app/(reverification)/actions.ts b/integration/templates/next-app-router/src/app/(reverification)/actions.ts index 89c8378894a..f281ffed632 100644 --- a/integration/templates/next-app-router/src/app/(reverification)/actions.ts +++ b/integration/templates/next-app-router/src/app/(reverification)/actions.ts @@ -1,7 +1,7 @@ 'use server'; import { auth } from '@clerk/nextjs/server'; -import { __experimental_reverificationMismatch as reverificationMismatch } from '@clerk/shared/authorization-errors'; +import { __experimental_reverificationError as reverificationError } from '@clerk/shared/authorization-errors'; import { __experimental_ReverificationConfig } from '@clerk/types'; const logUserIdActionReverification = async () => { @@ -17,7 +17,7 @@ const logUserIdActionReverification = async () => { }); if (userNeedsReverification) { - return reverificationMismatch(config); + return reverificationError(config); } return { diff --git a/packages/backend/src/__tests__/exports.test.ts b/packages/backend/src/__tests__/exports.test.ts index 836faf96f5c..0a9d5802292 100644 --- a/packages/backend/src/__tests__/exports.test.ts +++ b/packages/backend/src/__tests__/exports.test.ts @@ -37,8 +37,8 @@ describe('subpath /internal exports', () => { expect(Object.keys(internalExports).sort()).toMatchInlineSnapshot(` [ "AuthStatus", - "__experimental_reverificationMismatch", - "__experimental_reverificationMismatchResponse", + "__experimental_reverificationError", + "__experimental_reverificationErrorResponse", "constants", "createAuthenticateRequest", "createClerkRequest", diff --git a/packages/backend/src/internal.ts b/packages/backend/src/internal.ts index 73050b33bb9..e29158d637f 100644 --- a/packages/backend/src/internal.ts +++ b/packages/backend/src/internal.ts @@ -21,6 +21,6 @@ export { createClerkRequest } from './tokens/clerkRequest'; export type { ClerkRequest } from './tokens/clerkRequest'; export { - __experimental_reverificationMismatch, - __experimental_reverificationMismatchResponse, + __experimental_reverificationError, + __experimental_reverificationErrorResponse, } from '@clerk/shared/authorization-errors'; diff --git a/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap b/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap index 9f4e27aa8ee..77a73c84037 100644 --- a/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap +++ b/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap @@ -2,8 +2,8 @@ exports[`/server public exports > should not include a breaking change 1`] = ` [ - "__experimental_reverificationMismatch", - "__experimental_reverificationMismatchResponse", + "__experimental_reverificationError", + "__experimental_reverificationErrorResponse", "auth", "buildClerkProps", "clerkClient", diff --git a/packages/nextjs/src/server/index.ts b/packages/nextjs/src/server/index.ts index 83bcf62071a..686f72d0d72 100644 --- a/packages/nextjs/src/server/index.ts +++ b/packages/nextjs/src/server/index.ts @@ -68,6 +68,6 @@ export type { * Utilities for reverification */ export { - __experimental_reverificationMismatchResponse, - __experimental_reverificationMismatch, + __experimental_reverificationErrorResponse, + __experimental_reverificationError, } from '@clerk/backend/internal'; diff --git a/packages/shared/src/authorization-errors.ts b/packages/shared/src/authorization-errors.ts index 350e40dcb92..a94010bebbe 100644 --- a/packages/shared/src/authorization-errors.ts +++ b/packages/shared/src/authorization-errors.ts @@ -4,45 +4,50 @@ type ClerkError = { clerk_error: T; }; -type ReverificationMismatchError = ClerkError< +const REVERIFICATION_REASON = 'reverification-error'; + +type ReverificationError = ClerkError< { type: 'forbidden'; - reason: 'reverification-mismatch'; + reason: typeof REVERIFICATION_REASON; } & M >; -const __experimental_reverificationMismatch = (missingConfig?: MC) => - ({ - clerk_error: { - type: 'forbidden', - reason: 'reverification-mismatch', - metadata: { - reverification: missingConfig, - }, +const __experimental_reverificationError = ( + missingConfig?: MC, +): ReverificationError<{ + metadata: { + reverification?: MC; + }; +}> => ({ + clerk_error: { + type: 'forbidden', + reason: REVERIFICATION_REASON, + metadata: { + reverification: missingConfig, }, - }) satisfies ReverificationMismatchError; + }, +}); -const __experimental_reverificationMismatchResponse = ( - ...args: Parameters -) => - new Response(JSON.stringify(__experimental_reverificationMismatch(...args)), { +const __experimental_reverificationErrorResponse = (...args: Parameters) => + new Response(JSON.stringify(__experimental_reverificationError(...args)), { status: 403, }); const __experimental_isReverificationHint = ( result: any, -): result is ReturnType => { +): result is ReturnType => { return ( result && typeof result === 'object' && 'clerk_error' in result && result.clerk_error?.type === 'forbidden' && - result.clerk_error?.reason === 'reverification-mismatch' + result.clerk_error?.reason === REVERIFICATION_REASON ); }; export { - __experimental_reverificationMismatch, - __experimental_reverificationMismatchResponse, + __experimental_reverificationError, + __experimental_reverificationErrorResponse, __experimental_isReverificationHint, }; diff --git a/packages/shared/src/react/hooks/useReverification.ts b/packages/shared/src/react/hooks/useReverification.ts index 091ded297bc..74f3b87a82d 100644 --- a/packages/shared/src/react/hooks/useReverification.ts +++ b/packages/shared/src/react/hooks/useReverification.ts @@ -1,7 +1,7 @@ import type { Clerk } from '@clerk/types'; import { useMemo, useRef } from 'react'; -import { __experimental_isReverificationHint, __experimental_reverificationMismatch } from '../../authorization-errors'; +import { __experimental_isReverificationHint, __experimental_reverificationError } from '../../authorization-errors'; import { ClerkRuntimeError, isClerkAPIResponseError } from '../../error'; import { createDeferredPromise } from '../../utils/createDeferredPromise'; import { useClerk } from './useClerk'; @@ -9,7 +9,7 @@ import { useSafeLayoutEffect } from './useSafeLayoutEffect'; async function resolveResult( result: Promise, -): Promise> { +): Promise> { return result .then(r => { if (r instanceof Response) { @@ -20,7 +20,7 @@ async function resolveResult( .catch(e => { // Treat fapi assurance as an assurance hint if (isClerkAPIResponseError(e) && e.errors.find(({ code }) => code == 'session_step_up_verification_required')) { - return __experimental_reverificationMismatch(); + return __experimental_reverificationError(); } // rethrow