From 5fede0b2ff2ba584bd3af084f67457a5ae5730e2 Mon Sep 17 00:00:00 2001 From: Bryce Kalow Date: Tue, 18 Feb 2025 17:11:55 -0600 Subject: [PATCH 1/2] Align types between Clerk and IsomorphicClerk --- packages/react/src/isomorphicClerk.ts | 286 +++++++++----------------- 1 file changed, 97 insertions(+), 189 deletions(-) diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index 61b8c439cc9..85202601e3d 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -1,6 +1,5 @@ import { inBrowser } from '@clerk/shared/browser'; import { loadClerkJsScript } from '@clerk/shared/loadClerkJsScript'; -import type { TelemetryCollector } from '@clerk/shared/telemetry'; import { handleValueOrFn } from '@clerk/shared/utils'; import type { __internal_UserVerificationModalProps, @@ -19,7 +18,6 @@ import type { GoogleOneTapProps, HandleEmailLinkVerificationParams, HandleOAuthCallbackParams, - InstanceType, JoinWaitlistParams, ListenerCallback, LoadedClerk, @@ -28,22 +26,16 @@ import type { OrganizationResource, OrganizationSwitcherProps, RedirectOptions, - SDKMetadata, SetActiveParams, - SignedInSessionResource, SignInProps, SignInRedirectOptions, SignInResource, - SignOut, - SignOutCallback, - SignOutOptions, SignUpProps, SignUpRedirectOptions, SignUpResource, UnsubscribeCallback, UserButtonProps, UserProfileProps, - UserResource, WaitlistProps, WaitlistResource, Without, @@ -85,95 +77,17 @@ type MethodName = { type MethodCallback = () => Promise | unknown; +type WithVoidReturn any> = ( + ...args: Parameters +) => ReturnType extends Promise ? Promise : ReturnType | void; +type WithVoidReturnFunctions = { + [K in keyof T]: T[K] extends (...args: any) => any ? WithVoidReturn : T[K]; +}; + type IsomorphicLoadedClerk = Without< - LoadedClerk, - /** - * Override ClerkJS methods in order to support premountMethodCalls - */ - | 'buildSignInUrl' - | 'buildSignUpUrl' - | 'buildUserProfileUrl' - | 'buildCreateOrganizationUrl' - | 'buildOrganizationProfileUrl' - | 'buildAfterSignUpUrl' - | 'buildAfterSignInUrl' - | 'buildAfterSignOutUrl' - | 'buildAfterMultiSessionSingleSignOutUrl' - | 'buildUrlWithAuth' - | 'buildWaitlistUrl' - | 'handleRedirectCallback' - | 'handleGoogleOneTapCallback' - | 'handleUnauthenticated' - | 'authenticateWithMetamask' - | 'authenticateWithCoinbaseWallet' - | 'authenticateWithWeb3' - | 'authenticateWithGoogleOneTap' - | 'createOrganization' - | 'getOrganization' - | 'joinWaitlist' - | 'mountUserButton' - | 'mountOrganizationList' - | 'mountOrganizationSwitcher' - | 'mountOrganizationProfile' - | 'mountCreateOrganization' - | 'mountSignUp' - | 'mountSignIn' - | 'mountUserProfile' - | 'mountWaitlist' - | 'client' - | '__internal_getCachedResources' - | '__internal_reloadInitialResources' - | '__internal_addNavigationListener' + WithVoidReturnFunctions, + 'client' | '__internal_addNavigationListener' | '__internal_getCachedResources' | '__internal_reloadInitialResources' > & { - // TODO: Align return type and parms - handleRedirectCallback: (params: HandleOAuthCallbackParams) => void; - handleGoogleOneTapCallback: (signInOrUp: SignInResource | SignUpResource, params: HandleOAuthCallbackParams) => void; - handleUnauthenticated: () => void; - // TODO: Align Promise unknown - authenticateWithMetamask: (params: AuthenticateWithMetamaskParams) => Promise; - authenticateWithCoinbaseWallet: (params: AuthenticateWithCoinbaseWalletParams) => Promise; - authenticateWithOKXWallet: (params: AuthenticateWithOKXWalletParams) => Promise; - authenticateWithWeb3: (params: ClerkAuthenticateWithWeb3Params) => Promise; - authenticateWithGoogleOneTap: ( - params: AuthenticateWithGoogleOneTapParams, - ) => 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; - // TODO: Align return type - joinWaitlist: (params: JoinWaitlistParams) => Promise; - - // 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 - buildAfterSignInUrl: () => string | void; - // TODO: Align return type - buildAfterSignUpUrl: () => string | void; - // TODO: Align return type - buildAfterSignOutUrl: () => string | void; - // TODO: Align return type - buildAfterMultiSessionSingleSignOutUrl: () => string | void; - // TODO: Align optional props - buildWaitlistUrl: () => string | void; - // TODO: Align optional props - 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; - mountWaitlist: (node: HTMLDivElement, props: WaitlistProps) => void; client: ClientResource | undefined; }; @@ -190,16 +104,16 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { private preopenOrganizationProfile?: null | OrganizationProfileProps = null; private preopenCreateOrganization?: null | CreateOrganizationProps = null; private preOpenWaitlist?: null | WaitlistProps = null; - private premountSignInNodes = new Map(); - private premountSignUpNodes = new Map(); - private premountUserProfileNodes = new Map(); - private premountUserButtonNodes = new Map(); - private premountOrganizationProfileNodes = new Map(); - private premountCreateOrganizationNodes = new Map(); - private premountOrganizationSwitcherNodes = new Map(); - private premountOrganizationListNodes = new Map(); + private premountSignInNodes = new Map(); + private premountSignUpNodes = new Map(); + private premountUserProfileNodes = new Map(); + private premountUserButtonNodes = new Map(); + private premountOrganizationProfileNodes = new Map(); + private premountCreateOrganizationNodes = new Map(); + private premountOrganizationSwitcherNodes = new Map(); + private premountOrganizationListNodes = new Map(); private premountMethodCalls = new Map, MethodCallback>(); - private premountWaitlistNodes = new Map(); + private premountWaitlistNodes = new Map(); // A separate Map of `addListener` method calls to handle multiple listeners. private premountAddListenerCalls = new Map< ListenerCallback, @@ -292,23 +206,23 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } } - get sdkMetadata(): SDKMetadata | undefined { + get sdkMetadata() { return this.clerkjs?.sdkMetadata || this.options.sdkMetadata || undefined; } - get instanceType(): InstanceType | undefined { + get instanceType() { return this.clerkjs?.instanceType; } - get frontendApi(): string { + get frontendApi() { return this.clerkjs?.frontendApi || ''; } - get isStandardBrowser(): boolean { + get isStandardBrowser() { return this.clerkjs?.isStandardBrowser || this.options.standardBrowser || false; } - get isSatellite(): boolean { + get isSatellite() { // 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) { @@ -338,8 +252,8 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - buildAfterSignInUrl = (): string | void => { - const callback = () => this.clerkjs?.buildAfterSignInUrl() || ''; + buildAfterSignInUrl = (...args: Parameters): string | void => { + const callback = () => this.clerkjs?.buildAfterSignInUrl(...args) || ''; if (this.clerkjs && this.#loaded) { return callback(); } else { @@ -347,8 +261,8 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - buildAfterSignUpUrl = (): string | void => { - const callback = () => this.clerkjs?.buildAfterSignUpUrl() || ''; + buildAfterSignUpUrl = (...args: Parameters): string | void => { + const callback = () => this.clerkjs?.buildAfterSignUpUrl(...args) || ''; if (this.clerkjs && this.#loaded) { return callback(); } else { @@ -419,7 +333,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - handleUnauthenticated = (): void => { + handleUnauthenticated = async () => { const callback = () => this.clerkjs?.handleUnauthenticated(); if (this.clerkjs && this.#loaded) { void callback(); @@ -574,27 +488,27 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { clerkjs.openWaitlist(this.preOpenWaitlist); } - this.premountSignInNodes.forEach((props: SignInProps, node: HTMLDivElement) => { + this.premountSignInNodes.forEach((props, node) => { clerkjs.mountSignIn(node, props); }); - this.premountSignUpNodes.forEach((props: SignUpProps, node: HTMLDivElement) => { + this.premountSignUpNodes.forEach((props, node) => { clerkjs.mountSignUp(node, props); }); - this.premountUserProfileNodes.forEach((props: UserProfileProps, node: HTMLDivElement) => { + this.premountUserProfileNodes.forEach((props, node) => { clerkjs.mountUserProfile(node, props); }); - this.premountUserButtonNodes.forEach((props: UserButtonProps, node: HTMLDivElement) => { + this.premountUserButtonNodes.forEach((props, node) => { clerkjs.mountUserButton(node, props); }); - this.premountOrganizationListNodes.forEach((props: OrganizationListProps, node: HTMLDivElement) => { + this.premountOrganizationListNodes.forEach((props, node) => { clerkjs.mountOrganizationList(node, props); }); - this.premountWaitlistNodes.forEach((props: WaitlistProps, node: HTMLDivElement) => { + this.premountWaitlistNodes.forEach((props, node) => { clerkjs.mountWaitlist(node, props); }); @@ -603,7 +517,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { return this.clerkjs; }; - get version(): string | undefined { + get version() { return this.clerkjs?.version; } @@ -616,7 +530,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } } - get session(): SignedInSessionResource | undefined | null { + get session() { if (this.clerkjs) { return this.clerkjs.session; } else { @@ -624,7 +538,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } } - get user(): UserResource | undefined | null { + get user() { if (this.clerkjs) { return this.clerkjs.user; } else { @@ -632,7 +546,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } } - get organization(): OrganizationResource | undefined | null { + get organization() { if (this.clerkjs) { return this.clerkjs.organization; } else { @@ -640,9 +554,8 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } } - get telemetry(): TelemetryCollector | undefined { + get telemetry() { if (this.clerkjs) { - // @ts-expect-error -- We can't add the type here due to the TelemetryCollector type existing in shared, but the Clerk type existing in types return this.clerkjs.telemetry; } else { return undefined; @@ -685,15 +598,15 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { /** * `setActive` can be used to set the active session and/or organization. */ - setActive = ({ session, organization, beforeEmit, redirectUrl }: SetActiveParams): Promise => { + setActive = (params: SetActiveParams): Promise => { if (this.clerkjs) { - return this.clerkjs.setActive({ session, organization, beforeEmit, redirectUrl }); + return this.clerkjs.setActive(params); } else { return Promise.reject(); } }; - openSignIn = (props?: SignInProps): void => { + openSignIn = (props?: SignInProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openSignIn(props); } else { @@ -701,7 +614,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeSignIn = (): void => { + closeSignIn = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeSignIn(); } else { @@ -709,7 +622,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - __internal_openReverification = (props?: __internal_UserVerificationModalProps): void => { + __internal_openReverification = (props?: __internal_UserVerificationModalProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.__internal_openReverification(props); } else { @@ -717,7 +630,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - __internal_closeReverification = (): void => { + __internal_closeReverification = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.__internal_closeReverification(); } else { @@ -725,7 +638,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openGoogleOneTap = (props?: GoogleOneTapProps): void => { + openGoogleOneTap = (props?: GoogleOneTapProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openGoogleOneTap(props); } else { @@ -733,7 +646,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeGoogleOneTap = (): void => { + closeGoogleOneTap = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeGoogleOneTap(); } else { @@ -741,7 +654,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openUserProfile = (props?: UserProfileProps): void => { + openUserProfile = (props?: UserProfileProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openUserProfile(props); } else { @@ -749,7 +662,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeUserProfile = (): void => { + closeUserProfile = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeUserProfile(); } else { @@ -757,7 +670,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openOrganizationProfile = (props?: OrganizationProfileProps): void => { + openOrganizationProfile = (props?: OrganizationProfileProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openOrganizationProfile(props); } else { @@ -765,7 +678,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeOrganizationProfile = (): void => { + closeOrganizationProfile = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeOrganizationProfile(); } else { @@ -773,7 +686,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openCreateOrganization = (props?: CreateOrganizationProps): void => { + openCreateOrganization = (props?: CreateOrganizationProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openCreateOrganization(props); } else { @@ -781,7 +694,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeCreateOrganization = (): void => { + closeCreateOrganization = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeCreateOrganization(); } else { @@ -789,7 +702,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openWaitlist = (props?: WaitlistProps): void => { + openWaitlist = (props?: WaitlistProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openWaitlist(props); } else { @@ -797,7 +710,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeWaitlist = (): void => { + closeWaitlist = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeWaitlist(); } else { @@ -805,7 +718,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - openSignUp = (props?: SignUpProps): void => { + openSignUp = (props?: SignUpProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.openSignUp(props); } else { @@ -813,7 +726,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - closeSignUp = (): void => { + closeSignUp = () => { if (this.clerkjs && this.#loaded) { this.clerkjs.closeSignUp(); } else { @@ -821,7 +734,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountSignIn = (node: HTMLDivElement, props: SignInProps): void => { + mountSignIn = (node: HTMLDivElement, props?: SignInProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountSignIn(node, props); } else { @@ -829,7 +742,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountSignIn = (node: HTMLDivElement): void => { + unmountSignIn = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountSignIn(node); } else { @@ -837,7 +750,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountSignUp = (node: HTMLDivElement, props: SignUpProps): void => { + mountSignUp = (node: HTMLDivElement, props?: SignUpProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountSignUp(node, props); } else { @@ -845,7 +758,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountSignUp = (node: HTMLDivElement): void => { + unmountSignUp = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountSignUp(node); } else { @@ -853,7 +766,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountUserProfile = (node: HTMLDivElement, props: UserProfileProps): void => { + mountUserProfile = (node: HTMLDivElement, props?: UserProfileProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountUserProfile(node, props); } else { @@ -861,7 +774,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountUserProfile = (node: HTMLDivElement): void => { + unmountUserProfile = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountUserProfile(node); } else { @@ -869,7 +782,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountOrganizationProfile = (node: HTMLDivElement, props: OrganizationProfileProps): void => { + mountOrganizationProfile = (node: HTMLDivElement, props?: OrganizationProfileProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountOrganizationProfile(node, props); } else { @@ -877,7 +790,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountOrganizationProfile = (node: HTMLDivElement): void => { + unmountOrganizationProfile = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountOrganizationProfile(node); } else { @@ -885,7 +798,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountCreateOrganization = (node: HTMLDivElement, props: CreateOrganizationProps): void => { + mountCreateOrganization = (node: HTMLDivElement, props?: CreateOrganizationProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountCreateOrganization(node, props); } else { @@ -893,7 +806,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountCreateOrganization = (node: HTMLDivElement): void => { + unmountCreateOrganization = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountCreateOrganization(node); } else { @@ -901,7 +814,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountOrganizationSwitcher = (node: HTMLDivElement, props: OrganizationSwitcherProps): void => { + mountOrganizationSwitcher = (node: HTMLDivElement, props?: OrganizationSwitcherProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountOrganizationSwitcher(node, props); } else { @@ -909,7 +822,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountOrganizationSwitcher = (node: HTMLDivElement): void => { + unmountOrganizationSwitcher = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountOrganizationSwitcher(node); } else { @@ -917,7 +830,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - __experimental_prefetchOrganizationSwitcher = (): void => { + __experimental_prefetchOrganizationSwitcher = () => { const callback = () => this.clerkjs?.__experimental_prefetchOrganizationSwitcher(); if (this.clerkjs && this.#loaded) { void callback(); @@ -926,7 +839,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountOrganizationList = (node: HTMLDivElement, props: OrganizationListProps): void => { + mountOrganizationList = (node: HTMLDivElement, props?: OrganizationListProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountOrganizationList(node, props); } else { @@ -934,7 +847,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountOrganizationList = (node: HTMLDivElement): void => { + unmountOrganizationList = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountOrganizationList(node); } else { @@ -942,7 +855,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountUserButton = (node: HTMLDivElement, userButtonProps: UserButtonProps): void => { + mountUserButton = (node: HTMLDivElement, userButtonProps?: UserButtonProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountUserButton(node, userButtonProps); } else { @@ -950,7 +863,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountUserButton = (node: HTMLDivElement): void => { + unmountUserButton = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountUserButton(node); } else { @@ -958,7 +871,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - mountWaitlist = (node: HTMLDivElement, props: WaitlistProps): void => { + mountWaitlist = (node: HTMLDivElement, props?: WaitlistProps) => { if (this.clerkjs && this.#loaded) { this.clerkjs.mountWaitlist(node, props); } else { @@ -966,7 +879,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - unmountWaitlist = (node: HTMLDivElement): void => { + unmountWaitlist = (node: HTMLDivElement) => { if (this.clerkjs && this.#loaded) { this.clerkjs.unmountWaitlist(node); } else { @@ -990,7 +903,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - navigate = (to: string): void => { + navigate = (to: string) => { const callback = () => this.clerkjs?.navigate(to); if (this.clerkjs && this.#loaded) { void callback(); @@ -999,7 +912,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectWithAuth = async (...args: Parameters): Promise => { + redirectWithAuth = async (...args: Parameters) => { const callback = () => this.clerkjs?.redirectWithAuth(...args); if (this.clerkjs && this.#loaded) { return callback(); @@ -1009,7 +922,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToSignIn = async (opts: SignInRedirectOptions): Promise => { + redirectToSignIn = async (opts?: SignInRedirectOptions) => { const callback = () => this.clerkjs?.redirectToSignIn(opts as any); if (this.clerkjs && this.#loaded) { return callback(); @@ -1019,7 +932,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToSignUp = async (opts: SignUpRedirectOptions): Promise => { + redirectToSignUp = async (opts?: SignUpRedirectOptions) => { const callback = () => this.clerkjs?.redirectToSignUp(opts as any); if (this.clerkjs && this.#loaded) { return callback(); @@ -1029,7 +942,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToUserProfile = async (): Promise => { + redirectToUserProfile = async () => { const callback = () => this.clerkjs?.redirectToUserProfile(); if (this.clerkjs && this.#loaded) { return callback(); @@ -1048,7 +961,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToAfterSignIn = (): void => { + redirectToAfterSignIn = () => { const callback = () => this.clerkjs?.redirectToAfterSignIn(); if (this.clerkjs && this.#loaded) { callback(); @@ -1057,7 +970,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToAfterSignOut = (): void => { + redirectToAfterSignOut = () => { const callback = () => this.clerkjs?.redirectToAfterSignOut(); if (this.clerkjs && this.#loaded) { callback(); @@ -1066,7 +979,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToOrganizationProfile = async (): Promise => { + redirectToOrganizationProfile = async () => { const callback = () => this.clerkjs?.redirectToOrganizationProfile(); if (this.clerkjs && this.#loaded) { return callback(); @@ -1076,7 +989,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToCreateOrganization = async (): Promise => { + redirectToCreateOrganization = async () => { const callback = () => this.clerkjs?.redirectToCreateOrganization(); if (this.clerkjs && this.#loaded) { return callback(); @@ -1086,7 +999,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - redirectToWaitlist = async (): Promise => { + redirectToWaitlist = async () => { const callback = () => this.clerkjs?.redirectToWaitlist(); if (this.clerkjs && this.#loaded) { return callback(); @@ -1096,7 +1009,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - handleRedirectCallback = (params: HandleOAuthCallbackParams): void => { + handleRedirectCallback = async (params: HandleOAuthCallbackParams): Promise => { const callback = () => this.clerkjs?.handleRedirectCallback(params); if (this.clerkjs && this.#loaded) { void callback()?.catch(() => { @@ -1113,10 +1026,10 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - handleGoogleOneTapCallback = ( + handleGoogleOneTapCallback = async ( signInOrUp: SignInResource | SignUpResource, params: HandleOAuthCallbackParams, - ): void => { + ): Promise => { const callback = () => this.clerkjs?.handleGoogleOneTapCallback(signInOrUp, params); if (this.clerkjs && this.#loaded) { void callback()?.catch(() => { @@ -1133,7 +1046,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - handleEmailLinkVerification = async (params: HandleEmailLinkVerificationParams): Promise => { + handleEmailLinkVerification = async (params: HandleEmailLinkVerificationParams) => { const callback = () => this.clerkjs?.handleEmailLinkVerification(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; @@ -1142,7 +1055,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - authenticateWithMetamask = async (params: AuthenticateWithMetamaskParams): Promise => { + authenticateWithMetamask = async (params?: AuthenticateWithMetamaskParams) => { const callback = () => this.clerkjs?.authenticateWithMetamask(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; @@ -1151,7 +1064,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - authenticateWithCoinbaseWallet = async (params: AuthenticateWithCoinbaseWalletParams): Promise => { + authenticateWithCoinbaseWallet = async (params?: AuthenticateWithCoinbaseWalletParams) => { const callback = () => this.clerkjs?.authenticateWithCoinbaseWallet(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; @@ -1160,7 +1073,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - authenticateWithOKXWallet = async (params?: AuthenticateWithOKXWalletParams): Promise => { + authenticateWithOKXWallet = async (params?: AuthenticateWithOKXWalletParams) => { const callback = () => this.clerkjs?.authenticateWithOKXWallet(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; @@ -1169,7 +1082,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - authenticateWithWeb3 = async (params: ClerkAuthenticateWithWeb3Params): Promise => { + authenticateWithWeb3 = async (params: ClerkAuthenticateWithWeb3Params) => { const callback = () => this.clerkjs?.authenticateWithWeb3(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; @@ -1178,9 +1091,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - authenticateWithGoogleOneTap = async ( - params: AuthenticateWithGoogleOneTapParams, - ): Promise => { + authenticateWithGoogleOneTap = async (params: AuthenticateWithGoogleOneTapParams) => { const clerkjs = await this.#waitForClerkJS(); return clerkjs.authenticateWithGoogleOneTap(params); }; @@ -1212,11 +1123,8 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk { } }; - signOut: SignOut = async ( - signOutCallbackOrOptions?: SignOutCallback | SignOutOptions, - options?: SignOutOptions, - ): Promise => { - const callback = () => this.clerkjs?.signOut(signOutCallbackOrOptions as any, options); + signOut = async (...args: Parameters) => { + const callback = () => this.clerkjs?.signOut(...args); if (this.clerkjs && this.#loaded) { return callback() as Promise; } else { From a7247a84ebba16f91886152efca6a87925093774 Mon Sep 17 00:00:00 2001 From: Bryce Kalow Date: Tue, 18 Feb 2025 17:13:52 -0600 Subject: [PATCH 2/2] Adds changeset --- .changeset/new-pots-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/new-pots-itch.md diff --git a/.changeset/new-pots-itch.md b/.changeset/new-pots-itch.md new file mode 100644 index 00000000000..a4abea00242 --- /dev/null +++ b/.changeset/new-pots-itch.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-react': patch +--- + +Refactors `IsomorphicClerk` types to reduce unnecessary duplication between it and `Clerk`. Also relies more on the source types from `Clerk` to ensure `IsomorphicClerk` types match.