Skip to content

Commit

Permalink
fix(shared): Handle ATOB errors (#5029)
Browse files Browse the repository at this point in the history
Thanks @Wolfleader101 for your contribution!
  • Loading branch information
jacekradko authored Jan 28, 2025
1 parent 8dc2e63 commit a309be3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-crabs-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Catching ATOB errors in isPublishableKey
24 changes: 16 additions & 8 deletions packages/shared/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@ export function parsePublishableKey(
};
}

export function isPublishableKey(key: string) {
key = key || '';

const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX);

const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$');

return hasValidPrefix && hasValidFrontendApiPostfix;
/**
* Checks if the provided key is a valid publishable key.
*
* @param key - The key to be checked. Defaults to an empty string if not provided.
* @returns `true` if 'key' is a valid publishable key, `false` otherwise.
*/
export function isPublishableKey(key: string = '') {
try {
const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX);

const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$');

return hasValidPrefix && hasValidFrontendApiPostfix;
} catch {
return false;
}
}

export function createDevOrStagingUrlCache() {
Expand Down

0 comments on commit a309be3

Please sign in to comment.