Skip to content

Commit

Permalink
chore(*): Enforce publishableKey to IsomorphicClerkOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkl committed Nov 16, 2023
1 parent cc7cfba commit acafd5b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
1 change: 0 additions & 1 deletion integration/tests/next-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { appConfigs } from '../presets';
test.describe('next build @nextjs', () => {
test.describe.configure({ mode: 'parallel' });
let app: Application;
const output = [];

test.beforeAll(async () => {
app = await appConfigs.next.appRouter
Expand Down
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
1 change: 0 additions & 1 deletion packages/nextjs/src/pages/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function ClerkProvider({ children, ...props }: NextClerkProviderProps): J

return (
<ClerkNextOptionsProvider options={mergedProps}>
{/*@ts-expect-error*/}
<ReactClerkProvider
{...mergedProps}
initialState={initialState}
Expand Down
6 changes: 4 additions & 2 deletions packages/nextjs/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkProviderProps } from '@clerk/clerk-react';
import type { MultiDomainAndOrProxy } from '@clerk/types';
import type React from 'react';

export type NextClerkProviderProps = {
Expand All @@ -12,4 +13,5 @@ export type NextClerkProviderProps = {
* @default true
*/
__unstable_invokeMiddlewareOnAuthStateChange?: boolean;
} & IsomorphicClerkOptions;
} & Partial<ClerkProviderProps> &
MultiDomainAndOrProxy;
6 changes: 3 additions & 3 deletions packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const mergeNextClerkPropsWithEnv = (props: Omit<NextClerkProviderProps, '
publishableKey: props.publishableKey || process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY || '',
clerkJSUrl: props.clerkJSUrl || process.env.NEXT_PUBLIC_CLERK_JS,
clerkJSVersion: props.clerkJSVersion || process.env.NEXT_PUBLIC_CLERK_JS_VERSION,
proxyUrl: props.proxyUrl || process.env.NEXT_PUBLIC_CLERK_PROXY_URL || '',
domain: props.domain || process.env.NEXT_PUBLIC_CLERK_DOMAIN || '',
isSatellite: props.isSatellite || isTruthy(process.env.NEXT_PUBLIC_CLERK_IS_SATELLITE),
proxyUrl: props.proxyUrl || (process.env.NEXT_PUBLIC_CLERK_PROXY_URL as any), // added as any to cater issue with type resolution
domain: props.domain || (process.env.NEXT_PUBLIC_CLERK_DOMAIN as any), // added as any to cater issue with type resolution
isSatellite: props.isSatellite || (isTruthy(process.env.NEXT_PUBLIC_CLERK_IS_SATELLITE) as any), // added as any to cater issue with type resolution
signInUrl: props.signInUrl || process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || '',
signUpUrl: props.signUpUrl || process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || '',
afterSignInUrl: props.afterSignInUrl || process.env.NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL || '',
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
3 changes: 2 additions & 1 deletion packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { ClientResource } from './client';
import type { CustomPage } from './customPages';
import type { DisplayThemeJSON } from './json';
import type { LocalizationResource } from './localization';
import type { MultiDomainAndOrProxy } from './multiDomain';
import type { OAuthProvider, OAuthScope } from './oauth';
import type { OrganizationResource } from './organization';
import type { MembershipRole } from './organizationMembership';
Expand Down Expand Up @@ -524,7 +525,7 @@ export interface ClerkOptions {
* Defaults to false
*/
isInterstitial?: boolean;
isSatellite?: boolean | ((url: URL) => boolean);
isSatellite?: MultiDomainAndOrProxy['isSatellite'];
}

export interface Resources {
Expand Down
10 changes: 4 additions & 6 deletions packages/types/src/multiDomain.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,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 All @@ -12,16 +10,16 @@ type StringOrURLFnToString = string | ((url: URL) => string);
export type MultiDomainAndOrProxy =
| {
isSatellite?: never;
proxyUrl?: never | StringOrURLFnToString;
proxyUrl?: StringOrURLFnToString;
domain?: never;
}
| {
isSatellite: Exclude<ClerkOptions['isSatellite'], undefined>;
isSatellite: boolean | ((url: URL) => boolean);
proxyUrl?: never;
domain: StringOrURLFnToString;
}
| {
isSatellite: Exclude<ClerkOptions['isSatellite'], undefined>;
isSatellite: boolean | ((url: URL) => boolean);
proxyUrl: StringOrURLFnToString;
domain?: never;
};
Expand Down

0 comments on commit acafd5b

Please sign in to comment.