From 77d3734224d1fa2057885094874396194ffb17e9 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 00:00:39 +0200 Subject: [PATCH 1/7] fix(clerk-react): Missing methods and properties from IsomorphicClerk --- packages/react/src/isomorphicClerk.ts | 90 ++++++++++++++++++++++++++- packages/types/src/clerk.ts | 12 ++-- 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index 6ce2d3f79cd..c969ee903f6 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -4,6 +4,7 @@ import type { TelemetryCollector } from '@clerk/shared/telemetry'; import type { ActiveSessionResource, AuthenticateWithMetamaskParams, + BuildUrlWithAuthParams, Clerk, ClientResource, CreateOrganizationParams, @@ -11,11 +12,15 @@ import type { DomainOrProxyUrl, HandleEmailLinkVerificationParams, HandleOAuthCallbackParams, + InstanceType, ListenerCallback, + LoadedClerk, OrganizationListProps, OrganizationProfileProps, OrganizationResource, OrganizationSwitcherProps, + RedirectOptions, + SDKMetadata, SetActiveParams, SignInProps, SignInRedirectOptions, @@ -57,7 +62,52 @@ type MethodName = { type MethodCallback = () => Promise | unknown; -export class IsomorphicClerk { +type IsomorphicLoadedClerk = Omit< + LoadedClerk, + | 'redirectWithAuth' + | 'redirectToSignIn' + | 'redirectToSignUp' + | 'handleRedirectCallback' + | 'authenticateWithMetamask' + | 'createOrganization' + | 'getOrganization' + | 'mountUserButton' + | 'mountOrganizationList' + | 'mountOrganizationSwitcher' + | 'mountOrganizationProfile' + | 'mountCreateOrganization' + | 'mountSignUp' + | 'mountSignIn' + | 'mountUserProfile' + | 'client' +> & { + // TODO: Align return type + redirectWithAuth: (...args: Parameters) => void; + // TODO: Align return type + redirectToSignIn: (options: SignInRedirectOptions) => void; + // TODO: Align return type + redirectToSignUp: (options: SignUpRedirectOptions) => void; + // TODO: Align return type and parms + handleRedirectCallback: (params: HandleOAuthCallbackParams) => void; + // TODO: Align Promise unknown + authenticateWithMetamask: (params: AuthenticateWithMetamaskParams) => Promise; + // TODO: Align return type (maybe not possible or correct) + createOrganization: (params: CreateOrganizationParams) => Promise; + // TODO: Align return type (maybe not possible or correct) + getOrganization: (organizationId: string) => Promise; + + mountUserButton: (targetNode: HTMLDivElement, userButtonProps: UserButtonProps) => void; + mountOrganizationList: (targetNode: HTMLDivElement, props: OrganizationListProps) => void; + mountOrganizationSwitcher: (targetNode: HTMLDivElement, props: OrganizationSwitcherProps) => void; + mountOrganizationProfile: (targetNode: HTMLDivElement, props: OrganizationProfileProps) => void; + mountCreateOrganization: (targetNode: HTMLDivElement, props: CreateOrganizationProps) => void; + mountSignUp: (targetNode: HTMLDivElement, signUpProps: SignUpProps) => void; + mountSignIn: (targetNode: HTMLDivElement, signInProps: SignInProps) => void; + mountUserProfile: (targetNode: HTMLDivElement, userProfileProps: UserProfileProps) => void; + client: ClientResource | undefined; +}; + +export class IsomorphicClerk implements IsomorphicLoadedClerk { private readonly mode: 'browser' | 'server'; private readonly options: IsomorphicClerkOptions; private readonly Clerk: ClerkProp; @@ -144,6 +194,44 @@ export class IsomorphicClerk { void this.loadClerkJS(); } + /** + * These are missing from IsomorphicClerk. + * These need to be aligned because `useClerk` exported by `@clerk/clerk-react` returns LoadedClerk + * Calling `const {buildUrlWithAuth} = useClerk()` will result in a runtime error as the function does not exist + */ + sdkMetadata?: SDKMetadata | undefined; + frontendApi: string; + isSatellite: boolean; + instanceType?: InstanceType | undefined; + isStandardBrowser?: boolean | undefined; + buildUrlWithAuth(to: string, opts?: BuildUrlWithAuthParams | undefined): string { + throw new Error('Method not implemented.'); + } + buildSignInUrl(opts?: RedirectOptions | undefined): string { + throw new Error('Method not implemented.'); + } + buildSignUpUrl(opts?: RedirectOptions | undefined): string { + throw new Error('Method not implemented.'); + } + buildUserProfileUrl(): string { + throw new Error('Method not implemented.'); + } + buildCreateOrganizationUrl(): string { + throw new Error('Method not implemented.'); + } + buildOrganizationProfileUrl(): string { + throw new Error('Method not implemented.'); + } + buildHomeUrl(): string { + throw new Error('Method not implemented.'); + } + handleUnauthenticated: () => Promise; + isReady: () => boolean; + + /** + * END OF METHODS THAT NEED TO BE ALIGNED + */ + async loadClerkJS(): Promise { if (this.mode !== 'browser' || this.#loaded) { return; diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index c38968c9d0d..519a7b7c1e8 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -373,21 +373,25 @@ export interface Clerk { /** * Redirects to the configured URL where is mounted. */ + // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToUserProfile: () => void; /** * Redirects to the configured URL where is mounted. */ + // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToOrganizationProfile: () => void; /** * Redirects to the configured URL where is mounted. */ + // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToCreateOrganization: () => void; /** * Redirects to the configured home URL of the instance. */ + // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToHome: () => void; /** @@ -760,8 +764,8 @@ export type UserButtonProps = UserButtonProfileMode & { */ showName?: boolean; /** - Controls the default state of the UserButton - */ + Controls the default state of the UserButton + */ defaultOpen?: boolean; /** * Full URL or path to navigate after sign out is complete @@ -813,8 +817,8 @@ type CreateOrganizationMode = export type OrganizationSwitcherProps = CreateOrganizationMode & OrganizationProfileMode & { /** - Controls the default state of the OrganizationSwitcher - */ + Controls the default state of the OrganizationSwitcher + */ defaultOpen?: boolean; /** * By default, users can switch between organization and their personal account. From 4d73428e4d2123058d4ab113db6bce7dac8b0a9d Mon Sep 17 00:00:00 2001 From: Tom Milewski Date: Wed, 29 Nov 2023 01:20:39 -0800 Subject: [PATCH 2/7] fix(clerk-react): Fill out missing methods and properties from IsomorphicClerk (#2228) --- packages/react/src/isomorphicClerk.ts | 156 +++++++++++++++++++------- 1 file changed, 117 insertions(+), 39 deletions(-) diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index c969ee903f6..51a7884b385 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -64,6 +64,13 @@ type MethodCallback = () => Promise | unknown; type IsomorphicLoadedClerk = Omit< LoadedClerk, + | 'buildSignInUrl' + | 'buildSignUpUrl' + | 'buildUserProfileUrl' + | 'buildCreateOrganizationUrl' + | 'buildOrganizationProfileUrl' + | 'buildHomeUrl' + | 'buildUrlWithAuth' | 'redirectWithAuth' | 'redirectToSignIn' | 'redirectToSignUp' @@ -96,14 +103,29 @@ type IsomorphicLoadedClerk = Omit< // TODO: Align return type (maybe not possible or correct) getOrganization: (organizationId: string) => Promise; - mountUserButton: (targetNode: HTMLDivElement, userButtonProps: UserButtonProps) => void; - mountOrganizationList: (targetNode: HTMLDivElement, props: OrganizationListProps) => void; - mountOrganizationSwitcher: (targetNode: HTMLDivElement, props: OrganizationSwitcherProps) => void; - mountOrganizationProfile: (targetNode: HTMLDivElement, props: OrganizationProfileProps) => void; - mountCreateOrganization: (targetNode: HTMLDivElement, props: CreateOrganizationProps) => void; - mountSignUp: (targetNode: HTMLDivElement, signUpProps: SignUpProps) => void; - mountSignIn: (targetNode: HTMLDivElement, signInProps: SignInProps) => void; - mountUserProfile: (targetNode: HTMLDivElement, userProfileProps: UserProfileProps) => void; + // TODO: Align return type + buildSignInUrl: (opts?: RedirectOptions) => string | void; + // TODO: Align return type + buildSignUpUrl: (opts?: RedirectOptions) => string | void; + // TODO: Align return type + buildUserProfileUrl: () => string | void; + // TODO: Align return type + buildCreateOrganizationUrl: () => string | void; + // TODO: Align return type + buildOrganizationProfileUrl: () => string | void; + // TODO: Align return type + buildHomeUrl: () => string | void; + // TODO: Align return type + buildUrlWithAuth: (to: string, opts?: BuildUrlWithAuthParams | undefined) => string | void; + + mountUserButton: (node: HTMLDivElement, props: UserButtonProps) => void; + mountOrganizationList: (node: HTMLDivElement, props: OrganizationListProps) => void; + mountOrganizationSwitcher: (node: HTMLDivElement, props: OrganizationSwitcherProps) => void; + mountOrganizationProfile: (node: HTMLDivElement, props: OrganizationProfileProps) => void; + mountCreateOrganization: (node: HTMLDivElement, props: CreateOrganizationProps) => void; + mountSignUp: (node: HTMLDivElement, props: SignUpProps) => void; + mountSignIn: (node: HTMLDivElement, props: SignInProps) => void; + mountUserProfile: (node: HTMLDivElement, props: UserProfileProps) => void; client: ClientResource | undefined; }; @@ -194,43 +216,99 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { void this.loadClerkJS(); } - /** - * These are missing from IsomorphicClerk. - * These need to be aligned because `useClerk` exported by `@clerk/clerk-react` returns LoadedClerk - * Calling `const {buildUrlWithAuth} = useClerk()` will result in a runtime error as the function does not exist - */ - sdkMetadata?: SDKMetadata | undefined; - frontendApi: string; - isSatellite: boolean; - instanceType?: InstanceType | undefined; - isStandardBrowser?: boolean | undefined; - buildUrlWithAuth(to: string, opts?: BuildUrlWithAuthParams | undefined): string { - throw new Error('Method not implemented.'); - } - buildSignInUrl(opts?: RedirectOptions | undefined): string { - throw new Error('Method not implemented.'); + get sdkMetadata(): SDKMetadata | undefined { + return this.clerkjs?.sdkMetadata || this.options.sdkMetadata || undefined; } - buildSignUpUrl(opts?: RedirectOptions | undefined): string { - throw new Error('Method not implemented.'); - } - buildUserProfileUrl(): string { - throw new Error('Method not implemented.'); + + get instanceType(): InstanceType | undefined { + return this.clerkjs?.instanceType; } - buildCreateOrganizationUrl(): string { - throw new Error('Method not implemented.'); + + get frontendApi(): string { + return this.clerkjs?.frontendApi || ''; } - buildOrganizationProfileUrl(): string { - throw new Error('Method not implemented.'); + + get isStandardBrowser(): boolean { + return this.clerkjs?.isStandardBrowser || false; } - buildHomeUrl(): string { - throw new Error('Method not implemented.'); + + get isSatellite(): boolean { + return this.clerkjs?.isSatellite || false; } - handleUnauthenticated: () => Promise; - isReady: () => boolean; - /** - * END OF METHODS THAT NEED TO BE ALIGNED - */ + isReady = (): boolean => Boolean(this.clerkjs?.isReady()); + + buildSignInUrl = (opts?: RedirectOptions): string | void => { + const callback = () => this.clerkjs?.buildSignInUrl(opts) || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildSignInUrl', callback); + } + }; + + buildSignUpUrl = (opts?: RedirectOptions): string | void => { + const callback = () => this.clerkjs?.buildSignUpUrl(opts) || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildSignUpUrl', callback); + } + }; + + buildUserProfileUrl = (): string | void => { + const callback = () => this.clerkjs?.buildUserProfileUrl() || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildUserProfileUrl', callback); + } + }; + + buildCreateOrganizationUrl = (): string | void => { + const callback = () => this.clerkjs?.buildCreateOrganizationUrl() || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildCreateOrganizationUrl', callback); + } + }; + + buildOrganizationProfileUrl = (): string | void => { + const callback = () => this.clerkjs?.buildOrganizationProfileUrl() || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildOrganizationProfileUrl', callback); + } + }; + + buildHomeUrl = (): string | void => { + const callback = () => this.clerkjs?.buildHomeUrl() || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildHomeUrl', callback); + } + }; + + buildUrlWithAuth = (to: string, opts?: BuildUrlWithAuthParams | undefined): string | void => { + const callback = () => this.clerkjs?.buildUrlWithAuth(to, opts) || ''; + if (this.clerkjs && this.#loaded) { + return callback(); + } else { + this.premountMethodCalls.set('buildUrlWithAuth', callback); + } + }; + + handleUnauthenticated = async (): Promise => { + const callback = () => this.clerkjs?.handleUnauthenticated(); + if (this.clerkjs && this.#loaded) { + return callback() as Promise; + } else { + this.premountMethodCalls.set('handleUnauthenticated', callback); + } + }; async loadClerkJS(): Promise { if (this.mode !== 'browser' || this.#loaded) { From 0988c6ae58b4c8063fb2b730069921074eaf28cb Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 11:59:08 +0200 Subject: [PATCH 3/7] fix(clerk-react): Align implementation of isSatellite --- packages/react/src/errors.ts | 2 +- packages/react/src/isomorphicClerk.ts | 23 +++++++++++++++++++---- packages/types/src/clerk.ts | 5 +++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/react/src/errors.ts b/packages/react/src/errors.ts index 9ab1690fe69..498e47d2807 100644 --- a/packages/react/src/errors.ts +++ b/packages/react/src/errors.ts @@ -23,7 +23,7 @@ export const invalidStateError = 'Invalid state. Feel free to submit a bug or reach out to support here: https://clerk.com/support'; export const unsupportedNonBrowserDomainOrProxyUrlFunction = - 'Unsupported usage of domain or proxyUrl. The usage of domain or proxyUrl as function is not supported in non-browser environments.'; + 'Unsupported usage of isSatellite, domain or proxyUrl. The usage of isSatellite, domain or proxyUrl as function is not supported in non-browser environments.'; export const userProfilePageRenderedError = ' component needs to be a direct child of `` or ``.'; diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index 51a7884b385..6201ea82c4a 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -64,6 +64,9 @@ type MethodCallback = () => Promise | unknown; type IsomorphicLoadedClerk = Omit< LoadedClerk, + /** + * Override ClerkJS methods in order to support premountMethodCalls + */ | 'buildSignInUrl' | 'buildSignUpUrl' | 'buildUserProfileUrl' @@ -75,6 +78,7 @@ type IsomorphicLoadedClerk = Omit< | 'redirectToSignIn' | 'redirectToSignUp' | 'handleRedirectCallback' + | 'handleUnauthenticated' | 'authenticateWithMetamask' | 'createOrganization' | 'getOrganization' @@ -96,6 +100,7 @@ type IsomorphicLoadedClerk = Omit< redirectToSignUp: (options: SignUpRedirectOptions) => void; // TODO: Align return type and parms handleRedirectCallback: (params: HandleOAuthCallbackParams) => void; + handleUnauthenticated: () => void; // TODO: Align Promise unknown authenticateWithMetamask: (params: AuthenticateWithMetamaskParams) => Promise; // TODO: Align return type (maybe not possible or correct) @@ -118,6 +123,7 @@ type IsomorphicLoadedClerk = Omit< // TODO: Align return type buildUrlWithAuth: (to: string, opts?: BuildUrlWithAuthParams | undefined) => string | void; + // TODO: Align optional props mountUserButton: (node: HTMLDivElement, props: UserButtonProps) => void; mountOrganizationList: (node: HTMLDivElement, props: OrganizationListProps) => void; mountOrganizationSwitcher: (node: HTMLDivElement, props: OrganizationSwitcherProps) => void; @@ -224,16 +230,25 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { return this.clerkjs?.instanceType; } + // TODO: Ask Dimtris why is this still here get frontendApi(): string { return this.clerkjs?.frontendApi || ''; } get isStandardBrowser(): boolean { - return this.clerkjs?.isStandardBrowser || false; + return this.clerkjs?.isStandardBrowser || this.options.standardBrowser || false; } get isSatellite(): boolean { - return this.clerkjs?.isSatellite || false; + // This getter can run in environments where window is not available. + // In those cases we should expect and use domain as a string + if (typeof window !== 'undefined' && window.location) { + return handleValueOrFn(this.options.isSatellite, new URL(window.location.href), false); + } + if (typeof this.options.isSatellite === 'function') { + return errorThrower.throw(unsupportedNonBrowserDomainOrProxyUrlFunction); + } + return false; } isReady = (): boolean => Boolean(this.clerkjs?.isReady()); @@ -301,10 +316,10 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - handleUnauthenticated = async (): Promise => { + handleUnauthenticated = (): void => { const callback = () => this.clerkjs?.handleUnauthenticated(); if (this.clerkjs && this.#loaded) { - return callback() as Promise; + void callback(); } else { this.premountMethodCalls.set('handleUnauthenticated', callback); } diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index 519a7b7c1e8..f4ee16faba7 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -67,8 +67,12 @@ export interface Clerk { */ sdkMetadata?: SDKMetadata; + /** + * If true the bootstrapping of Clerk.load() has completed successfully. + */ loaded: boolean; + // TODO: Maybe remove ? frontendApi: string; /** Clerk Publishable Key string. */ @@ -434,6 +438,7 @@ export interface Clerk { /** * Returns true if bootstrapping with Clerk.load has completed successfully. Otherwise, returns false. */ + // TODO: Should we deprecate this ? isReady: () => boolean; } From 320a22d638cfd65ce4b38df7fb18e0297095fb85 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 12:11:01 +0200 Subject: [PATCH 4/7] fix(clerk-react): Add changeset --- .changeset/mean-poets-bow.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/mean-poets-bow.md diff --git a/.changeset/mean-poets-bow.md b/.changeset/mean-poets-bow.md new file mode 100644 index 00000000000..1c4c7d93e16 --- /dev/null +++ b/.changeset/mean-poets-bow.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': patch +'@clerk/clerk-react': patch +--- + +Sync IsomorphicClerk with the clerk singleton and the LoadedClerk interface. IsomorphicClerk now extends from LoadedClerk. From 915e6c7e379b60e89cc49416c38b06f67fc6d626 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 13:31:32 +0200 Subject: [PATCH 5/7] chore(clerk-react): Remove todos --- packages/react/src/isomorphicClerk.ts | 1 - packages/types/src/clerk.ts | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index 6201ea82c4a..219748babac 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -230,7 +230,6 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { return this.clerkjs?.instanceType; } - // TODO: Ask Dimtris why is this still here get frontendApi(): string { return this.clerkjs?.frontendApi || ''; } diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index f4ee16faba7..7b7576066e4 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -72,7 +72,6 @@ export interface Clerk { */ loaded: boolean; - // TODO: Maybe remove ? frontendApi: string; /** Clerk Publishable Key string. */ @@ -377,25 +376,21 @@ export interface Clerk { /** * Redirects to the configured URL where is mounted. */ - // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToUserProfile: () => void; /** * Redirects to the configured URL where is mounted. */ - // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToOrganizationProfile: () => void; /** * Redirects to the configured URL where is mounted. */ - // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToCreateOrganization: () => void; /** * Redirects to the configured home URL of the instance. */ - // TODO: why is this return void and the `redirectToSignUp` returns a Promise redirectToHome: () => void; /** @@ -438,7 +433,6 @@ export interface Clerk { /** * Returns true if bootstrapping with Clerk.load has completed successfully. Otherwise, returns false. */ - // TODO: Should we deprecate this ? isReady: () => boolean; } @@ -769,7 +763,7 @@ export type UserButtonProps = UserButtonProfileMode & { */ showName?: boolean; /** - Controls the default state of the UserButton + * Controls the default state of the UserButton */ defaultOpen?: boolean; /** @@ -822,8 +816,8 @@ type CreateOrganizationMode = export type OrganizationSwitcherProps = CreateOrganizationMode & OrganizationProfileMode & { /** - Controls the default state of the OrganizationSwitcher - */ + * Controls the default state of the OrganizationSwitcher + */ defaultOpen?: boolean; /** * By default, users can switch between organization and their personal account. From c0200b7c24b68f530ab75d8ec02553e4b0c314d6 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 16:26:25 +0200 Subject: [PATCH 6/7] fix(clerk-react): Replace optional Clerk properties with undefined --- packages/clerk-js/src/core/clerk.ts | 8 ++++---- packages/react/src/isomorphicClerk.ts | 3 ++- packages/types/src/clerk.ts | 18 +++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index 68f4cb3eba5..d2518b91651 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -146,10 +146,10 @@ export class Clerk implements ClerkInterface { version: __PKG_VERSION__, }; - public client?: ClientResource; - public session?: ActiveSessionResource | null; - public organization?: OrganizationResource | null; - public user?: UserResource | null; + public client: ClientResource | undefined; + public session: ActiveSessionResource | null | undefined; + public organization: OrganizationResource | null | undefined; + public user: UserResource | null | undefined; public __internal_country?: string | null; public telemetry?: TelemetryCollector; diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index 219748babac..c86e580bbeb 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -33,6 +33,7 @@ import type { UserButtonProps, UserProfileProps, UserResource, + Without, } from '@clerk/types'; import { unsupportedNonBrowserDomainOrProxyUrlFunction } from './errors'; @@ -62,7 +63,7 @@ type MethodName = { type MethodCallback = () => Promise | unknown; -type IsomorphicLoadedClerk = Omit< +type IsomorphicLoadedClerk = Without< LoadedClerk, /** * Override ClerkJS methods in order to support premountMethodCalls diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index 7b7576066e4..49ccab28433 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -59,13 +59,13 @@ export interface Clerk { /** * Clerk SDK version number. */ - version?: string; + version: string | undefined; /** * If present, contains information about the SDK that the host application is using. * For example, if Clerk is loaded through `@clerk/nextjs`, this would be `{ name: '@clerk/nextjs', version: '1.0.0' }` */ - sdkMetadata?: SDKMetadata; + sdkMetadata: SDKMetadata | undefined; /** * If true the bootstrapping of Clerk.load() has completed successfully. @@ -78,7 +78,7 @@ export interface Clerk { publishableKey: string; /** Clerk Proxy url string. */ - proxyUrl?: string; + proxyUrl: string | undefined; /** Clerk Satellite Frontend API string. */ domain: string; @@ -87,22 +87,22 @@ export interface Clerk { isSatellite: boolean; /** Clerk Instance type is defined from the Publishable key */ - instanceType?: InstanceType; + instanceType: InstanceType | undefined; /** Clerk flag for loading Clerk in a standard browser setup */ - isStandardBrowser?: boolean; + isStandardBrowser: boolean | undefined; /** Client handling most Clerk operations. */ - client?: ClientResource; + client: ClientResource | undefined; /** Active Session. */ - session?: ActiveSessionResource | null; + session: ActiveSessionResource | null | undefined; /** Active Organization */ - organization?: OrganizationResource | null; + organization: OrganizationResource | null | undefined; /** Current User. */ - user?: UserResource | null; + user: UserResource | null | undefined; /** * Signs out the current user on single-session instances, or all users on multi-session instances From 1eee5ed45b87bc1d0baef3f4815639430214d0b1 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 29 Nov 2023 17:39:50 +0200 Subject: [PATCH 7/7] fix(clerk-js): Add missing sdkMetadata getter --- packages/clerk-js/src/core/clerk.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index d2518b91651..43a403bf7f0 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -180,6 +180,10 @@ export class Clerk implements ClerkInterface { return Clerk.version; } + get sdkMetadata(): SDKMetadata { + return Clerk.sdkMetadata; + } + get loaded(): boolean { return this.#isReady; }