Skip to content

Commit

Permalink
chore(backend): Extract isomorphicAtob to separate file
Browse files Browse the repository at this point in the history
So it can also be used in extracting the bytes of a private key for
signing jwt tokens. Ideally this should be imported from @clerk/shared.
  • Loading branch information
Nikpolik committed Sep 26, 2023
1 parent 23c0739 commit 490e0e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 10 additions & 0 deletions packages/backend/src/shared/isomorphicAtob.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 2 additions & 9 deletions packages/backend/src/shared/parsePublishableKey.ts
Original file line number Diff line number Diff line change
@@ -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_';

Expand Down Expand Up @@ -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;
};

0 comments on commit 490e0e3

Please sign in to comment.