Skip to content

Commit da76490

Browse files
fix(shared): Generate publishable keys with unpadded Base64 encoding to match backend output (#8400)
1 parent 6be2ea9 commit da76490

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

.changeset/neat-keys-shine.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+
Generate publishable keys with unpadded Base64 encoding to match backend output.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515

1616
describe('buildPublishableKey(frontendApi)', () => {
1717
const cases = [
18-
['fake-clerk-test.clerk.accounts.dev', 'pk_live_ZmFrZS1jbGVyay10ZXN0LmNsZXJrLmFjY291bnRzLmRldiQ='],
18+
['fake-clerk-test.clerk.accounts.dev', 'pk_live_ZmFrZS1jbGVyay10ZXN0LmNsZXJrLmFjY291bnRzLmRldiQ'],
1919
['foo-bar-13.clerk.accounts.dev', 'pk_test_Zm9vLWJhci0xMy5jbGVyay5hY2NvdW50cy5kZXYk'],
20-
['clerk.boring.sawfly-91.lcl.dev', 'pk_test_Y2xlcmsuYm9yaW5nLnNhd2ZseS05MS5sY2wuZGV2JA=='],
20+
['clerk.boring.sawfly-91.lcl.dev', 'pk_test_Y2xlcmsuYm9yaW5nLnNhd2ZseS05MS5sY2wuZGV2JA'],
2121
['clerk.boring.sawfly-91.lclclerk.com', 'pk_test_Y2xlcmsuYm9yaW5nLnNhd2ZseS05MS5sY2xjbGVyay5jb20k'],
2222
];
2323

@@ -37,7 +37,7 @@ describe('parsePublishableKey(key)', () => {
3737
['', null],
3838
['whatever', null],
3939
[
40-
'pk_live_ZmFrZS1jbGVyay10ZXN0LmNsZXJrLmFjY291bnRzLmRldiQ=',
40+
'pk_live_ZmFrZS1jbGVyay10ZXN0LmNsZXJrLmFjY291bnRzLmRldiQ',
4141
{ instanceType: 'production', frontendApi: 'fake-clerk-test.clerk.accounts.dev' },
4242
],
4343
[

packages/shared/src/keys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ const PUBLISHABLE_KEY_TEST_PREFIX = 'pk_test_';
3030
const PUBLISHABLE_FRONTEND_API_DEV_REGEX = /^(([a-z]+)-){2}([0-9]{1,2})\.clerk\.accounts([a-z.]*)(dev|com)$/i;
3131

3232
/**
33-
* Converts a frontend API URL into a base64-encoded publishable key.
33+
* Converts a frontend API URL into an unpadded base64-encoded publishable key.
3434
*
3535
* @param frontendApi - The frontend API URL (e.g., 'clerk.example.com').
36-
* @returns A base64-encoded publishable key with appropriate prefix (pk_live_ or pk_test_).
36+
* @returns An unpadded base64-encoded publishable key with appropriate prefix (pk_live_ or pk_test_).
3737
*/
3838
export function buildPublishableKey(frontendApi: string): string {
3939
const isDevKey =
4040
PUBLISHABLE_FRONTEND_API_DEV_REGEX.test(frontendApi) ||
4141
(frontendApi.startsWith('clerk.') && LEGACY_DEV_INSTANCE_SUFFIXES.some(s => frontendApi.endsWith(s)));
4242
const keyPrefix = isDevKey ? PUBLISHABLE_KEY_TEST_PREFIX : PUBLISHABLE_KEY_LIVE_PREFIX;
43-
return `${keyPrefix}${isomorphicBtoa(`${frontendApi}$`)}`;
43+
return `${keyPrefix}${isomorphicBtoa(`${frontendApi}$`).replace(/=+$/, '')}`;
4444
}
4545

4646
/**

0 commit comments

Comments
 (0)