diff --git a/.changeset/tender-bears-design.md b/.changeset/tender-bears-design.md new file mode 100644 index 00000000000..372cac86a64 --- /dev/null +++ b/.changeset/tender-bears-design.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +isPublishableKey(key) catches atob error diff --git a/packages/shared/src/keys.ts b/packages/shared/src/keys.ts index f8f21489c07..e1ea3eee6b9 100644 --- a/packages/shared/src/keys.ts +++ b/packages/shared/src/keys.ts @@ -70,13 +70,17 @@ export function parsePublishableKey( } export function isPublishableKey(key: string) { - key = key || ''; + try { + key = key || ''; - const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX); + const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX); - const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$'); + const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$'); - return hasValidPrefix && hasValidFrontendApiPostfix; + return hasValidPrefix && hasValidFrontendApiPostfix; + } catch { + return false; + } } export function createDevOrStagingUrlCache() {