Skip to content

Commit

Permalink
fix(shared): Improve error message when Publishable Key is missing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anagstef authored Dec 17, 2024
1 parent 1a69e84 commit 84ccb00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/long-birds-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Improve error message when Publishable Key is missing when trying to parse it.
6 changes: 6 additions & 0 deletions packages/shared/src/__tests__/keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('parsePublishableKey(key)', () => {
expect(() => parsePublishableKey('fake_pk', { fatal: true })).toThrowError('Publishable key not valid.');
});

it('throws an error if the publishable key is missing, when fatal: true', () => {
expect(() => parsePublishableKey(undefined, { fatal: true })).toThrowError(
'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',
);
});

it('applies the proxyUrl if provided', () => {
expect(parsePublishableKey('pk_live_Y2xlcmsuY2xlcmsuZGV2JA==', { proxyUrl: 'example.com/__clerk' })).toEqual({
frontendApi: 'example.com/__clerk',
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export function parsePublishableKey(
key = key || '';

if (!key || !isPublishableKey(key)) {
if (options.fatal) {
if (options.fatal && !key) {
throw new Error(
'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',
);
}
if (options.fatal && !isPublishableKey(key)) {
throw new Error('Publishable key not valid.');
}
return null;
Expand Down

0 comments on commit 84ccb00

Please sign in to comment.