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