diff --git a/packages/backend/src/shared/isomorphicAtob.ts b/packages/backend/src/shared/isomorphicAtob.ts new file mode 100644 index 00000000000..d18f12c20af --- /dev/null +++ b/packages/backend/src/shared/isomorphicAtob.ts @@ -0,0 +1,10 @@ +const isomorphicAtob = (data: string) => { + if (typeof atob !== 'undefined' && typeof atob === 'function') { + return atob(data); + } else if (typeof globalThis !== 'undefined' && globalThis.Buffer) { + return globalThis.Buffer.from(data, 'base64').toString(); + } + return data; +}; + +export default isomorphicAtob; diff --git a/packages/backend/src/shared/parsePublishableKey.ts b/packages/backend/src/shared/parsePublishableKey.ts index 19e2ad66eb4..333c6c6565f 100644 --- a/packages/backend/src/shared/parsePublishableKey.ts +++ b/packages/backend/src/shared/parsePublishableKey.ts @@ -1,5 +1,7 @@ import type { PublishableKey } from '@clerk/types'; +import isomorphicAtob from './isomorphicAtob'; + const PUBLISHABLE_KEY_LIVE_PREFIX = 'pk_live_'; const PUBLISHABLE_KEY_TEST_PREFIX = 'pk_test_'; @@ -45,12 +47,3 @@ export function isPublishableKey(key: string) { return hasValidPrefix && hasValidFrontendApiPostfix; } - -const isomorphicAtob = (data: string) => { - if (typeof atob !== 'undefined' && typeof atob === 'function') { - return atob(data); - } else if (typeof globalThis !== 'undefined' && globalThis.Buffer) { - return new globalThis.Buffer(data, 'base64').toString(); - } - return data; -};