Skip to content

Commit 844847e

Browse files
authoredDec 12, 2023
chore(clerk-react,types): Align return types for redirectTo methods in ClerkJS [SDK-1037] (#2316)
1 parent 896cb61 commit 844847e

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed
 

‎.changeset/witty-forks-cheer.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@clerk/clerk-react': major
3+
'@clerk/types': major
4+
---
5+
6+
Align return types for redirectTo* methods in ClerkJS [SDK-1037]
7+
8+
Breaking Changes:
9+
10+
- `redirectToUserProfile` now returns `Promise<unknown>` instead of `void`
11+
- `redirectToOrganizationProfile` now returns `Promise<unknown>` instead of `void`
12+
- `redirectToCreateOrganization` now returns `Promise<unknown>` instead of `void`
13+
- `redirectToHome` now returns `Promise<unknown>` instead of `void`

‎packages/react/src/components/controlComponents.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,23 @@ export const RedirectToSignUp = withClerk(({ clerk, ...props }: WithClerkProp<Re
159159

160160
export const RedirectToUserProfile = withClerk(({ clerk }) => {
161161
React.useEffect(() => {
162-
clerk.redirectToUserProfile();
162+
void clerk.redirectToUserProfile();
163163
}, []);
164164

165165
return null;
166166
}, 'RedirectToUserProfile');
167167

168168
export const RedirectToOrganizationProfile = withClerk(({ clerk }) => {
169169
React.useEffect(() => {
170-
clerk.redirectToOrganizationProfile();
170+
void clerk.redirectToOrganizationProfile();
171171
}, []);
172172

173173
return null;
174174
}, 'RedirectToOrganizationProfile');
175175

176176
export const RedirectToCreateOrganization = withClerk(({ clerk }) => {
177177
React.useEffect(() => {
178-
clerk.redirectToCreateOrganization();
178+
void clerk.redirectToCreateOrganization();
179179
}, []);
180180

181181
return null;

‎packages/react/src/isomorphicClerk.ts

+21-23
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ type IsomorphicLoadedClerk = Without<
7575
| 'buildOrganizationProfileUrl'
7676
| 'buildHomeUrl'
7777
| 'buildUrlWithAuth'
78-
| 'redirectWithAuth'
79-
| 'redirectToSignIn'
80-
| 'redirectToSignUp'
8178
| 'handleRedirectCallback'
8279
| 'handleUnauthenticated'
8380
| 'authenticateWithMetamask'
@@ -93,12 +90,6 @@ type IsomorphicLoadedClerk = Without<
9390
| 'mountUserProfile'
9491
| 'client'
9592
> & {
96-
// TODO: Align return type
97-
redirectWithAuth: (...args: Parameters<Clerk['redirectWithAuth']>) => void;
98-
// TODO: Align return type
99-
redirectToSignIn: (options: SignInRedirectOptions) => void;
100-
// TODO: Align return type
101-
redirectToSignUp: (options: SignUpRedirectOptions) => void;
10293
// TODO: Align return type and parms
10394
handleRedirectCallback: (params: HandleOAuthCallbackParams) => void;
10495
handleUnauthenticated: () => void;
@@ -777,66 +768,73 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
777768
}
778769
};
779770

780-
redirectWithAuth = (...args: Parameters<Clerk['redirectWithAuth']>): void => {
771+
redirectWithAuth = async (...args: Parameters<Clerk['redirectWithAuth']>): Promise<unknown> => {
781772
const callback = () => this.clerkjs?.redirectWithAuth(...args);
782773
if (this.clerkjs && this.#loaded) {
783-
void callback();
774+
return callback();
784775
} else {
785776
this.premountMethodCalls.set('redirectWithAuth', callback);
777+
return;
786778
}
787779
};
788780

789-
redirectToSignIn = (opts: SignInRedirectOptions): void => {
781+
redirectToSignIn = async (opts: SignInRedirectOptions): Promise<unknown> => {
790782
const callback = () => this.clerkjs?.redirectToSignIn(opts as any);
791783
if (this.clerkjs && this.#loaded) {
792-
void callback();
784+
return callback();
793785
} else {
794786
this.premountMethodCalls.set('redirectToSignIn', callback);
787+
return;
795788
}
796789
};
797790

798-
redirectToSignUp = (opts: SignUpRedirectOptions): void => {
791+
redirectToSignUp = async (opts: SignUpRedirectOptions): Promise<unknown> => {
799792
const callback = () => this.clerkjs?.redirectToSignUp(opts as any);
800793
if (this.clerkjs && this.#loaded) {
801-
void callback();
794+
return callback();
802795
} else {
803796
this.premountMethodCalls.set('redirectToSignUp', callback);
797+
return;
804798
}
805799
};
806800

807-
redirectToUserProfile = (): void => {
801+
redirectToUserProfile = async (): Promise<unknown> => {
808802
const callback = () => this.clerkjs?.redirectToUserProfile();
809803
if (this.clerkjs && this.#loaded) {
810-
callback();
804+
return callback();
811805
} else {
812806
this.premountMethodCalls.set('redirectToUserProfile', callback);
807+
return;
813808
}
814809
};
815810

816-
redirectToHome = (): void => {
811+
redirectToHome = async (): Promise<unknown> => {
817812
const callback = () => this.clerkjs?.redirectToHome();
818813
if (this.clerkjs && this.#loaded) {
819-
callback();
814+
return callback();
820815
} else {
821816
this.premountMethodCalls.set('redirectToHome', callback);
817+
return;
822818
}
823819
};
824820

825-
redirectToOrganizationProfile = (): void => {
821+
redirectToOrganizationProfile = async (): Promise<unknown> => {
826822
const callback = () => this.clerkjs?.redirectToOrganizationProfile();
827823
if (this.clerkjs && this.#loaded) {
828-
callback();
824+
return callback();
829825
} else {
830826
this.premountMethodCalls.set('redirectToOrganizationProfile', callback);
827+
return;
831828
}
832829
};
833830

834-
redirectToCreateOrganization = (): void => {
831+
redirectToCreateOrganization = async (): Promise<unknown> => {
835832
const callback = () => this.clerkjs?.redirectToCreateOrganization();
836833
if (this.clerkjs && this.#loaded) {
837-
callback();
834+
return callback();
838835
} else {
839836
this.premountMethodCalls.set('redirectToCreateOrganization', callback);
837+
return;
840838
}
841839
};
842840

‎packages/types/src/clerk.retheme.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,22 @@ export interface Clerk {
371371
/**
372372
* Redirects to the configured URL where <UserProfile/> is mounted.
373373
*/
374-
redirectToUserProfile: () => void;
374+
redirectToUserProfile: () => Promise<unknown>;
375375

376376
/**
377377
* Redirects to the configured URL where <OrganizationProfile /> is mounted.
378378
*/
379-
redirectToOrganizationProfile: () => void;
379+
redirectToOrganizationProfile: () => Promise<unknown>;
380380

381381
/**
382382
* Redirects to the configured URL where <CreateOrganization /> is mounted.
383383
*/
384-
redirectToCreateOrganization: () => void;
384+
redirectToCreateOrganization: () => Promise<unknown>;
385385

386386
/**
387387
* Redirects to the configured home URL of the instance.
388388
*/
389-
redirectToHome: () => void;
389+
redirectToHome: () => Promise<unknown>;
390390

391391
/**
392392
* Completes an OAuth or SAML redirection flow started by

‎packages/types/src/clerk.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,22 @@ export interface Clerk {
371371
/**
372372
* Redirects to the configured URL where <UserProfile/> is mounted.
373373
*/
374-
redirectToUserProfile: () => void;
374+
redirectToUserProfile: () => Promise<unknown>;
375375

376376
/**
377377
* Redirects to the configured URL where <OrganizationProfile /> is mounted.
378378
*/
379-
redirectToOrganizationProfile: () => void;
379+
redirectToOrganizationProfile: () => Promise<unknown>;
380380

381381
/**
382382
* Redirects to the configured URL where <CreateOrganization /> is mounted.
383383
*/
384-
redirectToCreateOrganization: () => void;
384+
redirectToCreateOrganization: () => Promise<unknown>;
385385

386386
/**
387387
* Redirects to the configured home URL of the instance.
388388
*/
389-
redirectToHome: () => void;
389+
redirectToHome: () => Promise<unknown>;
390390

391391
/**
392392
* Completes an OAuth or SAML redirection flow started by

0 commit comments

Comments
 (0)
Please sign in to comment.