@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
1 lines • 1.7 kB
Source Map (JSON)
{"version":3,"file":"authorization-errors.mjs","names":[],"sources":["../src/authorization-errors.ts"],"sourcesContent":["import type { ReverificationConfig } from './types';\n\ntype ClerkError<T> = {\n clerk_error: T;\n};\n\nconst REVERIFICATION_REASON = 'reverification-error';\n\ntype ReverificationError<M extends { metadata?: any } = { metadata: unknown }> = ClerkError<\n {\n type: 'forbidden';\n reason: typeof REVERIFICATION_REASON;\n } & M\n>;\n\nconst reverificationError = <MC extends ReverificationConfig>(\n missingConfig?: MC,\n): ReverificationError<{\n metadata?: {\n reverification?: MC;\n };\n}> => ({\n clerk_error: {\n type: 'forbidden',\n reason: REVERIFICATION_REASON,\n metadata: {\n reverification: missingConfig,\n },\n },\n});\n\nconst reverificationErrorResponse = (...args: Parameters<typeof reverificationError>) =>\n new Response(JSON.stringify(reverificationError(...args)), {\n status: 403,\n });\n\nconst isReverificationHint = (result: any): result is ReturnType<typeof reverificationError> => {\n return (\n result &&\n typeof result === 'object' &&\n 'clerk_error' in result &&\n result.clerk_error?.type === 'forbidden' &&\n result.clerk_error?.reason === REVERIFICATION_REASON\n );\n};\n\nexport { isReverificationHint, reverificationError, reverificationErrorResponse };\n"],"mappings":";AAMA,MAAM,wBAAwB;AAS9B,MAAM,uBACJ,mBAKK,EACL,aAAa;CACX,MAAM;CACN,QAAQ;CACR,UAAU,EACR,gBAAgB,cAClB;AACF,EACF;AAEA,MAAM,+BAA+B,GAAG,SACtC,IAAI,SAAS,KAAK,UAAU,oBAAoB,GAAG,IAAI,CAAC,GAAG,EACzD,QAAQ,IACV,CAAC;AAEH,MAAM,wBAAwB,WAAkE;CAC9F,OACE,UACA,OAAO,WAAW,YAClB,iBAAiB,UACjB,OAAO,aAAa,SAAS,eAC7B,OAAO,aAAa,WAAW;AAEnC"}