Skip to content

Commit 84ccb00

Browse files
authored
fix(shared): Improve error message when Publishable Key is missing (#4785)
1 parent 1a69e84 commit 84ccb00

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.changeset/long-birds-worry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': patch
3+
---
4+
5+
Improve error message when Publishable Key is missing when trying to parse it.

packages/shared/src/__tests__/keys.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ describe('parsePublishableKey(key)', () => {
5858
expect(() => parsePublishableKey('fake_pk', { fatal: true })).toThrowError('Publishable key not valid.');
5959
});
6060

61+
it('throws an error if the publishable key is missing, when fatal: true', () => {
62+
expect(() => parsePublishableKey(undefined, { fatal: true })).toThrowError(
63+
'Publishable key is missing. Ensure that your publishable key is correctly configured. Double-check your environment configuration for your keys, or access them here: https://dashboard.clerk.com/last-active?path=api-keys',
64+
);
65+
});
66+
6167
it('applies the proxyUrl if provided', () => {
6268
expect(parsePublishableKey('pk_live_Y2xlcmsuY2xlcmsuZGV2JA==', { proxyUrl: 'example.com/__clerk' })).toEqual({
6369
frontendApi: 'example.com/__clerk',

packages/shared/src/keys.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export function parsePublishableKey(
3939
key = key || '';
4040

4141
if (!key || !isPublishableKey(key)) {
42-
if (options.fatal) {
42+
if (options.fatal && !key) {
43+
throw new Error(
44+
'Publishable key is missing. Ensure that your publishable key is correctly configured. Double-check your environment configuration for your keys, or access them here: https://dashboard.clerk.com/last-active?path=api-keys',
45+
);
46+
}
47+
if (options.fatal && !isPublishableKey(key)) {
4348
throw new Error('Publishable key not valid.');
4449
}
4550
return null;

0 commit comments

Comments
 (0)