Skip to content

Commit a309be3

Browse files
authored
fix(shared): Handle ATOB errors (#5029)
Thanks @Wolfleader101 for your contribution!
1 parent 8dc2e63 commit a309be3

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.changeset/clever-crabs-smell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': patch
3+
---
4+
5+
Catching ATOB errors in isPublishableKey

packages/shared/src/keys.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,22 @@ export function parsePublishableKey(
6969
};
7070
}
7171

72-
export function isPublishableKey(key: string) {
73-
key = key || '';
74-
75-
const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX);
76-
77-
const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$');
78-
79-
return hasValidPrefix && hasValidFrontendApiPostfix;
72+
/**
73+
* Checks if the provided key is a valid publishable key.
74+
*
75+
* @param key - The key to be checked. Defaults to an empty string if not provided.
76+
* @returns `true` if 'key' is a valid publishable key, `false` otherwise.
77+
*/
78+
export function isPublishableKey(key: string = '') {
79+
try {
80+
const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX);
81+
82+
const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$');
83+
84+
return hasValidPrefix && hasValidFrontendApiPostfix;
85+
} catch {
86+
return false;
87+
}
8088
}
8189

8290
export function createDevOrStagingUrlCache() {

0 commit comments

Comments
 (0)