Skip to content

Commit

Permalink
fix(clerk-react): Make publishableKey required in IsomorphicClerkOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkl committed Nov 15, 2023
1 parent cc7cfba commit 2961583
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
6 changes: 5 additions & 1 deletion packages/expo/src/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ __internal__setErrorThrowerOptions({
packageName: '@clerk/expo',
});

export type ClerkProviderProps = ClerkReactProviderProps & {
type ClerkReactProviderOptionalPK = Exclude<ClerkReactProviderProps, 'publishableKey'> &
Partial<Pick<ClerkReactProviderProps, 'publishableKey'>>;

export type ClerkProviderProps = ClerkReactProviderOptionalPK & {
tokenCache?: TokenCache;
};

Expand All @@ -27,6 +30,7 @@ export function ClerkProvider(props: ClerkProviderProps): JSX.Element {
// See JS-598 for additional context.
key={key}
{...rest}
publishableKey={key}
Clerk={buildClerk({ key, tokenCache })}
standardBrowser={!isReactNative()}
>
Expand Down
4 changes: 3 additions & 1 deletion packages/nextjs/src/app-router/server/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithE
import { ClientClerkProvider } from '../client/ClerkProvider';
import { initialState } from './auth';

type NextAppClerkProviderProps = React.PropsWithChildren<IsomorphicClerkOptions>;
type NextAppClerkProviderProps = React.PropsWithChildren<
Exclude<IsomorphicClerkOptions, 'publishableKey'> & { publishableKey?: string }
>;

export function ClerkProvider(props: NextAppClerkProviderProps) {
const { children, ...rest } = props;
Expand Down
17 changes: 15 additions & 2 deletions packages/nextjs/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkOptions, MultiDomainAndOrProxy } from '@clerk/types';
import type React from 'react';

export type NextClerkProviderProps = {
children: React.ReactNode;
/**
Expand All @@ -12,4 +12,17 @@ export type NextClerkProviderProps = {
* @default true
*/
__unstable_invokeMiddlewareOnAuthStateChange?: boolean;
} & IsomorphicClerkOptions;
} & /**
* TODO(@dimkl) The following code is a dirty hack to by-pass some type issues when using
* Exclude and Omit due.
* The actual code should be:
* ```
* export type NextClerkProviderProps = {
* __unstable_invokeMiddlewareOnAuthStateChange?: boolean;
* } & WithOptional<ClerkProviderProps, 'publishableKey'>;
* ```
*/ Omit<ClerkOptions, 'isSatellite'> &
MultiDomainAndOrProxy &
Pick<IsomorphicClerkOptions, 'Clerk' | 'clerkJSUrl' | 'clerkJSVariant' | 'clerkJSVersion' | 'sdkMetadata'> & {
publishableKey?: string;
};
2 changes: 1 addition & 1 deletion packages/react/src/contexts/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ClerkProviderProps = IsomorphicClerkOptions & {

function ClerkProviderBase(props: ClerkProviderProps): JSX.Element {
const { initialState, children, ...restIsomorphicClerkOptions } = props;
const { publishableKey = '', Clerk: userInitialisedClerk } = restIsomorphicClerkOptions;
const { publishableKey, Clerk: userInitialisedClerk } = restIsomorphicClerkOptions;

if (!userInitialisedClerk) {
if (!publishableKey) {
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
HandleOAuthCallbackParams,
ListenerCallback,
OrganizationListProps,
OrganizationMembershipResource,
OrganizationProfileProps,
OrganizationResource,
OrganizationSwitcherProps,
Expand Down Expand Up @@ -128,7 +127,7 @@ export default class IsomorphicClerk {

constructor(options: IsomorphicClerkOptions) {
const { Clerk = null, publishableKey } = options || {};
this.#publishableKey = publishableKey || '';
this.#publishableKey = publishableKey;
this.#proxyUrl = options?.proxyUrl;
this.#domain = options?.domain;
this.options = options;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type IsomorphicClerkOptions = Omit<ClerkOptions, 'isSatellite'> & {
clerkJSVariant?: 'headless' | '';
clerkJSVersion?: string;
sdkMetadata?: SDKMetadata;
publishableKey?: string;
publishableKey: string;
} & MultiDomainAndOrProxy;

export interface BrowserClerkConstructor {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/multiDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ClerkOptions } from './clerk';
type StringOrURLFnToString = string | ((url: URL) => string);

/**
* DomainOrProxyUrl supports the following cases
* MultiDomainAndOrProxy supports the following cases
* 1) none of them are set
* 2) only proxyUrl is set
* 3) isSatellite and proxy is set
Expand Down

0 comments on commit 2961583

Please sign in to comment.