Skip to content

Commit f540e98

Browse files
authoredMar 29, 2024··
fix(clerk-js,types): Fix the redirection that happens when SSO fails (#2955)
* fix(clerk-js,types): Fix the redirection that happens when SSO fails
1 parent 1fd2eff commit f540e98

File tree

7 files changed

+34
-4
lines changed

7 files changed

+34
-4
lines changed
 

‎.changeset/tame-coats-repeat.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Return to localhost when SSO callback fails on SignIn or SignUp

‎packages/clerk-js/src/core/clerk.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,9 @@ export class Clerk implements ClerkInterface {
10191019

10201020
const makeNavigate = (to: string) => () => navigate(to);
10211021

1022-
const navigateToSignIn = makeNavigate(displayConfig.signInUrl);
1022+
const navigateToSignIn = makeNavigate(params.signInUrl || displayConfig.signInUrl);
10231023

1024-
const navigateToSignUp = makeNavigate(displayConfig.signUpUrl);
1024+
const navigateToSignUp = makeNavigate(params.signUpUrl || displayConfig.signUpUrl);
10251025

10261026
const navigateToFactorOne = makeNavigate(
10271027
params.firstFactorUrl ||

‎packages/clerk-js/src/ui/components/SignIn/SignIn.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function SignInRoutes(): JSX.Element {
4242
</Route>
4343
<Route path='sso-callback'>
4444
<SignInSSOCallback
45+
signUpUrl={signInContext.signUpUrl}
46+
signInUrl={signInContext.signInUrl}
4547
afterSignInUrl={signInContext.afterSignInUrl}
4648
afterSignUpUrl={signInContext.afterSignUpUrl}
4749
redirectUrl={signInContext.redirectUrl}

‎packages/clerk-js/src/ui/components/SignUp/SignUp.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ function SignUpRoutes(): JSX.Element {
4040
</Route>
4141
<Route path='sso-callback'>
4242
<SignUpSSOCallback
43+
signUpUrl={signUpContext.signUpUrl}
44+
signInUrl={signUpContext.signInUrl}
4345
afterSignUpUrl={signUpContext.afterSignUpUrl}
4446
afterSignInUrl={signUpContext.afterSignInUrl}
4547
redirectUrl={signUpContext.redirectUrl}

‎packages/clerk-js/src/ui/contexts/ClerkUIComponentsContext.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ export const useSignUpContext = (): SignUpContextType => {
9191
displayConfig: displayConfig,
9292
});
9393

94-
let signUpUrl = pickRedirectionProp('signUpUrl', { ctx, options, displayConfig }, false);
94+
// The `ctx` object here refers to the SignUp component's props.
95+
// SignUp's own options won't have a `signUpUrl` property, so we have to get the value
96+
// from the `path` prop instead, when the routing is set to 'path'.
97+
let signUpUrl =
98+
(ctx.routing === 'path' ? ctx.path : undefined) ||
99+
pickRedirectionProp('signUpUrl', { options, displayConfig }, false);
95100
if (authQs && ctx.routing !== 'virtual') {
96101
signUpUrl += `#/?${authQs}`;
97102
}
@@ -175,7 +180,12 @@ export const useSignInContext = (): SignInContextType => {
175180
signUpUrl += `#/?${authQs}`;
176181
}
177182

178-
let signInUrl = pickRedirectionProp('signInUrl', { ctx, options, displayConfig }, false);
183+
// The `ctx` object here refers to the SignIn component's props.
184+
// SignIn's own options won't have a `signInUrl` property, so we have to get the value
185+
// from the `path` prop instead, when the routing is set to 'path'.
186+
let signInUrl =
187+
(ctx.routing === 'path' ? ctx.path : undefined) ||
188+
pickRedirectionProp('signInUrl', { options, displayConfig }, false);
179189
if (authQs && ctx.routing !== 'virtual') {
180190
signInUrl += `#/?${authQs}`;
181191
}

‎packages/elements/src/internals/machines/third-party/actors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export const handleRedirectCallback = fromCallback<AnyEventObject, HandleRedirec
8888
secondFactorUrl: ClerkJSNavigationEvent.signIn,
8989
verifyEmailAddressUrl: ClerkJSNavigationEvent.verification,
9090
verifyPhoneNumberUrl: ClerkJSNavigationEvent.verification,
91+
signUpUrl: ClerkJSNavigationEvent.signUp,
92+
signInUrl: ClerkJSNavigationEvent.signIn,
9193
} satisfies Required<HandleOAuthCallbackParams>,
9294
customNavigate,
9395
);

‎packages/types/src/clerk.ts

+8
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,14 @@ export interface Clerk {
451451
}
452452

453453
export type HandleOAuthCallbackParams = AfterActionURLs & {
454+
/**
455+
* Full URL or path where the SignIn component is mounted.
456+
*/
457+
signInUrl?: string;
458+
/**
459+
* Full URL or path where the SignUp component is mounted.
460+
*/
461+
signUpUrl?: string;
454462
/**
455463
* Full URL or path to navigate after successful sign in
456464
* or sign up.

0 commit comments

Comments
 (0)
Please sign in to comment.