Skip to content

Commit f1be1fe

Browse files
authored
fix(clerk-js,types): Fix stale SignIn on authenticateWithRedirect for enterprise_sso (#6160)
1 parent 65ca8f5 commit f1be1fe

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

.changeset/grumpy-lamps-study.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Fixes stale `SignIn` object on `authenticateWithRedirect` for `saml` and `enterprise_sso` custom flows
7+
8+
Previously, the same connection identifier would be used on every `authenticateWithRedirect` call leading to redirecting to the wrong identity provider

packages/clerk-js/src/core/resources/SignIn.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,27 @@ export class SignIn extends BaseResource implements SignInResource {
231231
params: AuthenticateWithRedirectParams,
232232
navigateCallback: (url: URL | string) => void,
233233
): Promise<void> => {
234-
const { strategy, redirectUrl, redirectUrlComplete, identifier, oidcPrompt } = params || {};
235-
236-
const { firstFactorVerification } =
237-
(strategy === 'saml' || strategy === 'enterprise_sso') && this.id
238-
? await this.prepareFirstFactor({
239-
strategy,
240-
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
241-
actionCompleteRedirectUrl: redirectUrlComplete,
242-
oidcPrompt,
243-
})
244-
: await this.create({
245-
strategy,
246-
identifier,
247-
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
248-
actionCompleteRedirectUrl: redirectUrlComplete,
249-
oidcPrompt,
250-
});
251-
252-
const { status, externalVerificationRedirectURL } = firstFactorVerification;
234+
const { strategy, redirectUrl, redirectUrlComplete, identifier, oidcPrompt, continueSignIn } = params || {};
235+
236+
if (!this.id || !continueSignIn) {
237+
await this.create({
238+
strategy,
239+
identifier,
240+
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
241+
actionCompleteRedirectUrl: redirectUrlComplete,
242+
});
243+
}
244+
245+
if (strategy === 'saml' || strategy === 'enterprise_sso') {
246+
await this.prepareFirstFactor({
247+
strategy,
248+
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
249+
actionCompleteRedirectUrl: redirectUrlComplete,
250+
oidcPrompt,
251+
});
252+
}
253+
254+
const { status, externalVerificationRedirectURL } = this.firstFactorVerification;
253255

254256
if (status === 'unverified' && externalVerificationRedirectURL) {
255257
navigateCallback(externalVerificationRedirectURL);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ function SignInStartInternal(): JSX.Element {
405405
redirectUrl,
406406
redirectUrlComplete,
407407
oidcPrompt: ctx.oidcPrompt,
408+
continueSignIn: true,
408409
});
409410
};
410411

packages/clerk-js/src/ui/components/SignIn/__tests__/SignInStart.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ describe('SignInStart', () => {
291291
strategy: 'enterprise_sso',
292292
redirectUrl: 'http://localhost/#/sso-callback',
293293
redirectUrlComplete: '/',
294+
continueSignIn: true,
294295
});
295296
});
296297
});
@@ -314,6 +315,7 @@ describe('SignInStart', () => {
314315
strategy: 'enterprise_sso',
315316
redirectUrl: 'http://localhost/#/sso-callback',
316317
redirectUrlComplete: '/',
318+
continueSignIn: true,
317319
});
318320
});
319321
});

packages/types/src/redirects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export type AuthenticateWithRedirectParams = {
6161
*/
6262
continueSignUp?: boolean;
6363

64+
/**
65+
* Whether to continue existing SignIn (if present) or create a new SignIn.
66+
*/
67+
continueSignIn?: boolean;
68+
6469
/**
6570
* One of the supported OAuth providers you can use to authenticate with, eg 'oauth_google'.
6671
* Alternatively `saml` or `enterprise_sso`, to authenticate with Enterprise SSO.

0 commit comments

Comments
 (0)