Skip to content

Commit

Permalink
fix(clerk-js,types): Fix the redirection that happens when SSO fails (#…
Browse files Browse the repository at this point in the history
…2955)

* fix(clerk-js,types): Fix the redirection that happens when SSO fails
  • Loading branch information
anagstef authored Mar 29, 2024
1 parent 1fd2eff commit f540e98
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/tame-coats-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Return to localhost when SSO callback fails on SignIn or SignUp
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ export class Clerk implements ClerkInterface {

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

const navigateToSignIn = makeNavigate(displayConfig.signInUrl);
const navigateToSignIn = makeNavigate(params.signInUrl || displayConfig.signInUrl);

const navigateToSignUp = makeNavigate(displayConfig.signUpUrl);
const navigateToSignUp = makeNavigate(params.signUpUrl || displayConfig.signUpUrl);

const navigateToFactorOne = makeNavigate(
params.firstFactorUrl ||
Expand Down
2 changes: 2 additions & 0 deletions packages/clerk-js/src/ui/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function SignInRoutes(): JSX.Element {
</Route>
<Route path='sso-callback'>
<SignInSSOCallback
signUpUrl={signInContext.signUpUrl}
signInUrl={signInContext.signInUrl}
afterSignInUrl={signInContext.afterSignInUrl}
afterSignUpUrl={signInContext.afterSignUpUrl}
redirectUrl={signInContext.redirectUrl}
Expand Down
2 changes: 2 additions & 0 deletions packages/clerk-js/src/ui/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function SignUpRoutes(): JSX.Element {
</Route>
<Route path='sso-callback'>
<SignUpSSOCallback
signUpUrl={signUpContext.signUpUrl}
signInUrl={signUpContext.signInUrl}
afterSignUpUrl={signUpContext.afterSignUpUrl}
afterSignInUrl={signUpContext.afterSignInUrl}
redirectUrl={signUpContext.redirectUrl}
Expand Down
14 changes: 12 additions & 2 deletions packages/clerk-js/src/ui/contexts/ClerkUIComponentsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export const useSignUpContext = (): SignUpContextType => {
displayConfig: displayConfig,
});

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

let signInUrl = pickRedirectionProp('signInUrl', { ctx, options, displayConfig }, false);
// The `ctx` object here refers to the SignIn component's props.
// SignIn's own options won't have a `signInUrl` property, so we have to get the value
// from the `path` prop instead, when the routing is set to 'path'.
let signInUrl =
(ctx.routing === 'path' ? ctx.path : undefined) ||
pickRedirectionProp('signInUrl', { options, displayConfig }, false);
if (authQs && ctx.routing !== 'virtual') {
signInUrl += `#/?${authQs}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const handleRedirectCallback = fromCallback<AnyEventObject, HandleRedirec
secondFactorUrl: ClerkJSNavigationEvent.signIn,
verifyEmailAddressUrl: ClerkJSNavigationEvent.verification,
verifyPhoneNumberUrl: ClerkJSNavigationEvent.verification,
signUpUrl: ClerkJSNavigationEvent.signUp,
signInUrl: ClerkJSNavigationEvent.signIn,
} satisfies Required<HandleOAuthCallbackParams>,
customNavigate,
);
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,14 @@ export interface Clerk {
}

export type HandleOAuthCallbackParams = AfterActionURLs & {
/**
* Full URL or path where the SignIn component is mounted.
*/
signInUrl?: string;
/**
* Full URL or path where the SignUp component is mounted.
*/
signUpUrl?: string;
/**
* Full URL or path to navigate after successful sign in
* or sign up.
Expand Down

0 comments on commit f540e98

Please sign in to comment.