From d84d7e31235c5c7da3415981dc76db4473a71a39 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 22 Nov 2024 14:14:42 -0500 Subject: [PATCH] chore(shared): Gracefully handle missing reverification error metadata (#4636) --- .changeset/many-bees-mate.md | 5 +++++ packages/shared/src/authorization-errors.ts | 2 +- packages/shared/src/authorization.ts | 6 +++++- packages/shared/src/react/hooks/useReverification.ts | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/many-bees-mate.md diff --git a/.changeset/many-bees-mate.md b/.changeset/many-bees-mate.md new file mode 100644 index 0000000000..1ec82dc473 --- /dev/null +++ b/.changeset/many-bees-mate.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +Gracefully handle missing reverification error metadata diff --git a/packages/shared/src/authorization-errors.ts b/packages/shared/src/authorization-errors.ts index bedcf8c386..9caa20411d 100644 --- a/packages/shared/src/authorization-errors.ts +++ b/packages/shared/src/authorization-errors.ts @@ -16,7 +16,7 @@ type ReverificationError = const reverificationError = ( missingConfig?: MC, ): ReverificationError<{ - metadata: { + metadata?: { reverification?: MC; }; }> => ({ diff --git a/packages/shared/src/authorization.ts b/packages/shared/src/authorization.ts index f09d5129fe..0e6a7c33da 100644 --- a/packages/shared/src/authorization.ts +++ b/packages/shared/src/authorization.ts @@ -79,7 +79,11 @@ const checkOrgAuthorization: CheckOrgAuthorization = (params, options) => { return null; }; -const validateReverificationConfig = (config: ReverificationConfig | undefined) => { +const validateReverificationConfig = (config: ReverificationConfig | undefined | null) => { + if (!config) { + return false; + } + const convertConfigToObject = (config: ReverificationConfig) => { if (typeof config === 'string') { return TYPES_TO_OBJECTS[config]; diff --git a/packages/shared/src/react/hooks/useReverification.ts b/packages/shared/src/react/hooks/useReverification.ts index 61bf6fd3a9..cbf7a6e160 100644 --- a/packages/shared/src/react/hooks/useReverification.ts +++ b/packages/shared/src/react/hooks/useReverification.ts @@ -52,7 +52,7 @@ function createReverificationHandler(params: CreateReverificationHandlerParams) */ const resolvers = createDeferredPromise(); - const isValidMetadata = validateReverificationConfig(result.clerk_error.metadata.reverification); + const isValidMetadata = validateReverificationConfig(result.clerk_error.metadata?.reverification); /** * On success resolve the pending promise