Skip to content

Commit 0ebecdf

Browse files
committed
chore(clerk-js,types): Address PR comments
1 parent d71797f commit 0ebecdf

7 files changed

Lines changed: 29 additions & 9 deletions

File tree

packages/clerk-js/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ There are two ways you can include ClerkJS in your project. You can either [impo
4444
npm install @clerk/clerk-js
4545
```
4646

47-
Once you have installed the package, you will need to import the ClerkJS object constructor into your code and pass it your [Frontend API](https://dashboard.clerk.com/last-active?path=api-keys) as a parameter.
47+
Once you have installed the package, you will need to import the ClerkJS object constructor into your code and pass it your [Publishable Key](https://dashboard.clerk.com/last-active?path=api-keys) as a parameter.
4848

4949
```js
5050
import Clerk from '@clerk/clerk-js';

packages/clerk-js/src/core/clerk.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ describe('Clerk singleton', () => {
133133
eventBus.off(events.TokenUpdate);
134134
});
135135

136+
describe('initialize', () => {
137+
it('should consider publishableKey readonly', () => {
138+
const sut = new Clerk(productionPublishableKey);
139+
expect(sut.publishableKey).toEqual(productionPublishableKey);
140+
141+
expect(() => {
142+
// @ts-expect-error attempt to override getter field
143+
sut.publishableKey = 'aloha';
144+
}).toThrowError(/Cannot set property publishableKey of #<Clerk>/);
145+
});
146+
147+
it('should throw when publishableKey is invalid', () => {
148+
expect(() => {
149+
new Clerk('invalidPK');
150+
}).toThrowError(/The publishableKey passed to Clerk is invalid/);
151+
});
152+
});
153+
136154
describe('.setActive', () => {
137155
const mockSession = {
138156
id: '1',

packages/clerk-js/src/core/clerk.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ export default class Clerk implements ClerkInterface {
147147
public organization?: OrganizationResource | null;
148148
public user?: UserResource | null;
149149
public __internal_country?: string | null;
150-
public readonly publishableKey: string = '';
151150

152151
protected internal_last_error: ClerkAPIError | null = null;
153152

153+
#publishableKey: string = '';
154154
#domain: DomainOrProxyUrl['domain'];
155155
#proxyUrl: DomainOrProxyUrl['proxyUrl'];
156156
#authService: SessionCookieService | null = null;
@@ -168,6 +168,10 @@ export default class Clerk implements ClerkInterface {
168168
#options: ClerkOptions = {};
169169
#pageLifecycle: ReturnType<typeof createPageLifecycle> | null = null;
170170

171+
get publishableKey(): string {
172+
return this.#publishableKey;
173+
}
174+
171175
get version(): string {
172176
return Clerk.version;
173177
}
@@ -239,7 +243,7 @@ export default class Clerk implements ClerkInterface {
239243
return errorThrower.throwInvalidPublishableKeyError({ key });
240244
}
241245

242-
this.publishableKey = key;
246+
this.#publishableKey = key;
243247
this.#instanceType = publishableKey.instanceType;
244248

245249
this.#fapiClient = createFapiClient(this);

packages/clerk-js/src/core/fapiClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Clerk } from '@clerk/types';
33
import createFapiClient from './fapiClient';
44

55
const mockedClerkInstance = {
6-
frontendApi: 'clerk.example.com', // publishableKey: 'pk_test_Y2xlcmsuZXhhbXBsZS5jb20k',
6+
frontendApi: 'clerk.example.com',
77
version: '42.0.0',
88
session: {
99
id: 'deadbeef',

packages/clerk-js/src/ui-retheme/components/UserButton/useMultisessionActions.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
6464
return signOut(opts.navigateAfterSignOut);
6565
};
6666

67-
// TODO: Fix this eslint error
68-
6967
const handleSessionClicked = (session: ActiveSessionResource) => async () => {
7068
card.setLoading();
7169
return setActive({ session, beforeEmit: opts.navigateAfterSwitchSession }).finally(() => {

packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
5151
return signOut(opts.navigateAfterSignOut);
5252
};
5353

54-
// TODO: Fix this eslint error
55-
5654
const handleSessionClicked = (session: ActiveSessionResource) => async () => {
5755
card.setLoading();
5856
return setActive({ session, beforeEmit: opts.navigateAfterSwitchSession }).finally(() => {

packages/types/src/jwt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export interface JWT {
66
claims: JWTClaims;
77
}
88

9+
type NonEmptyArray<T> = [T, ...T[]];
10+
911
// standard names https://www.rfc-editor.org/rfc/rfc7515.html#section-4.1
1012
export interface JWTHeader {
1113
alg: string | Algorithm;
1214
typ?: string;
1315
cty?: string;
14-
crit?: Array<string | Exclude<JWTHeader, 'crit'>>;
16+
crit?: NonEmptyArray<Exclude<keyof JWTHeader, 'crit'>>;
1517
kid?: string;
1618
jku?: string;
1719
x5u?: string | string[];

0 commit comments

Comments
 (0)