Skip to content

Commit c8e69db

Browse files
authored
fix(clerk-js): Don't use ctx SSO url if routing is virtual (#5562)
1 parent 5f3cc46 commit c8e69db

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.changeset/hot-cats-smell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix issue where the SSO callback URL was incorrectly generated when using the transfer flow within a modal.

packages/clerk-js/src/ui/common/__tests__/redirects.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,16 @@ describe('buildSSOCallbackURL(ctx, baseUrl)', () => {
209209
).toBe('http://test.host/#/sso-callback?redirect_url=%2Ffoo');
210210

211211
// Custom SSO callback URL in the context
212-
expect(buildSSOCallbackURL({ ssoCallbackUrl: 'http://test.host/ctx-sso-callback' })).toBe(
212+
expect(buildSSOCallbackURL({ isCombinedFlow: true, ssoCallbackUrl: 'http://test.host/ctx-sso-callback' })).toBe(
213213
'http://test.host/ctx-sso-callback',
214214
);
215+
// Does not use SSO callback URL from context when routing is virtual
216+
expect(
217+
buildSSOCallbackURL({
218+
isCombinedFlow: true,
219+
ssoCallbackUrl: 'http://test.host/ctx-sso-callback',
220+
routing: 'virtual',
221+
}),
222+
).toBe('http://localhost/#/sso-callback');
215223
});
216224
});

packages/clerk-js/src/ui/common/redirects.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ export function buildSSOCallbackURL(
5454
ctx: Partial<SignInContextType | SignUpContextType>,
5555
baseUrl: string | undefined = '',
5656
): string {
57+
const { routing, authQueryString, path } = ctx;
5758
// If the context contains an SSO callback URL, use it instead of building a new one, as it likely contains the
58-
// combined flow path.
59-
if ('ssoCallbackUrl' in ctx && ctx.ssoCallbackUrl) {
59+
// combined flow path. However, if the routing is virtual, the callback URL from context will not have factored in
60+
// baseUrl, so we fallback to buildRedirectUrl instead.
61+
if (ctx.ssoCallbackUrl && ctx.isCombinedFlow && routing !== 'virtual') {
6062
return ctx.ssoCallbackUrl;
6163
}
62-
const { routing, authQueryString, path } = ctx;
6364
return buildRedirectUrl({
6465
routing,
6566
baseUrl,

0 commit comments

Comments
 (0)