Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fluffy-tools-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/backend': minor
'@clerk/nextjs': minor
'@clerk/shared': minor
---

Rename `reverificationMismatch` to `reverificationError`.
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -17,7 +17,7 @@ const logUserIdActionReverification = async () => {
});

if (userNeedsReverification) {
return reverificationMismatch(config);
return reverificationError(config);
}

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/__tests__/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export type {
* Utilities for reverification
*/
export {
__experimental_reverificationMismatchResponse,
__experimental_reverificationMismatch,
__experimental_reverificationErrorResponse,
__experimental_reverificationError,
} from '@clerk/backend/internal';
43 changes: 24 additions & 19 deletions packages/shared/src/authorization-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,50 @@ type ClerkError<T> = {
clerk_error: T;
};

type ReverificationMismatchError<M extends { metadata?: any } = { metadata: unknown }> = ClerkError<
const REVERIFICATION_REASON = 'reverification-error';

type ReverificationError<M extends { metadata?: any } = { metadata: unknown }> = ClerkError<
{
type: 'forbidden';
reason: 'reverification-mismatch';
reason: typeof REVERIFICATION_REASON;
} & M
>;

const __experimental_reverificationMismatch = <MC extends __experimental_ReverificationConfig>(missingConfig?: MC) =>
({
clerk_error: {
type: 'forbidden',
reason: 'reverification-mismatch',
metadata: {
reverification: missingConfig,
},
const __experimental_reverificationError = <MC extends __experimental_ReverificationConfig>(
missingConfig?: MC,
): ReverificationError<{
metadata: {
reverification?: MC;
};
}> => ({
clerk_error: {
type: 'forbidden',
reason: REVERIFICATION_REASON,
metadata: {
reverification: missingConfig,
},
}) satisfies ReverificationMismatchError;
},
});

const __experimental_reverificationMismatchResponse = (
...args: Parameters<typeof __experimental_reverificationMismatch>
) =>
new Response(JSON.stringify(__experimental_reverificationMismatch(...args)), {
const __experimental_reverificationErrorResponse = (...args: Parameters<typeof __experimental_reverificationError>) =>
new Response(JSON.stringify(__experimental_reverificationError(...args)), {
status: 403,
});

const __experimental_isReverificationHint = (
result: any,
): result is ReturnType<typeof __experimental_reverificationMismatch> => {
): result is ReturnType<typeof __experimental_reverificationError> => {
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,
};
6 changes: 3 additions & 3 deletions packages/shared/src/react/hooks/useReverification.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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';
import { useSafeLayoutEffect } from './useSafeLayoutEffect';

async function resolveResult<T>(
result: Promise<T>,
): Promise<T | ReturnType<typeof __experimental_reverificationMismatch>> {
): Promise<T | ReturnType<typeof __experimental_reverificationError>> {
return result
.then(r => {
if (r instanceof Response) {
Expand All @@ -20,7 +20,7 @@ async function resolveResult<T>(
.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
Expand Down