Skip to content

Commit 3219cf7

Browse files
committed
Create fresh SignIn on authenticateWithRedirect call
1 parent 26d273c commit 3219cf7

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

.changeset/spicy-toes-behave.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fixes stale `SignIn` object on `authenticateWithRedirect` for `saml` and `enterprise_sso` custom flows
6+
7+
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: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,31 @@ export class SignIn extends BaseResource implements SignInResource {
224224
});
225225
};
226226

227-
public authenticateWithRedirect = async (params: AuthenticateWithRedirectParams): Promise<void> => {
228-
const { strategy, redirectUrl, redirectUrlComplete, identifier } = params || {};
229-
230-
const { firstFactorVerification } =
231-
(strategy === 'saml' || strategy === 'enterprise_sso') && this.id
232-
? await this.prepareFirstFactor({
233-
strategy,
234-
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
235-
actionCompleteRedirectUrl: redirectUrlComplete,
236-
})
237-
: await this.create({
238-
strategy,
239-
identifier,
240-
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
241-
actionCompleteRedirectUrl: redirectUrlComplete,
242-
});
243-
244-
const { status, externalVerificationRedirectURL } = firstFactorVerification;
227+
public authenticateWithRedirect = async ({
228+
strategy,
229+
redirectUrl,
230+
redirectUrlComplete,
231+
identifier,
232+
continueSignIn = false,
233+
}: AuthenticateWithRedirectParams): Promise<void> => {
234+
if (!this.id || !continueSignIn) {
235+
await this.create({
236+
strategy,
237+
identifier,
238+
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
239+
actionCompleteRedirectUrl: redirectUrlComplete,
240+
});
241+
}
242+
243+
if (strategy === 'saml' || strategy === 'enterprise_sso') {
244+
await this.prepareFirstFactor({
245+
strategy,
246+
redirectUrl: SignIn.clerk.buildUrlWithAuth(redirectUrl),
247+
actionCompleteRedirectUrl: redirectUrlComplete,
248+
});
249+
}
250+
251+
const { status, externalVerificationRedirectURL } = this.firstFactorVerification;
245252

246253
if (status === 'unverified' && externalVerificationRedirectURL) {
247254
windowNavigate(externalVerificationRedirectURL);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export function _SignInStart(): JSX.Element {
336336
strategy: 'enterprise_sso',
337337
redirectUrl,
338338
redirectUrlComplete,
339+
continueSignIn: true,
339340
});
340341
};
341342

packages/types/src/redirects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export type AuthenticateWithRedirectParams = {
6464
*/
6565
continueSignUp?: boolean;
6666

67+
/**
68+
* Whether to continue existing SignIn (if present) or create a new SignIn.
69+
*/
70+
continueSignIn?: boolean;
71+
6772
/**
6873
* One of the supported OAuth providers you can use to authenticate with, eg 'oauth_google'.
6974
* Alternatively `saml` or `enterprise_sso`, to authenticate with Enterprise SSO.

0 commit comments

Comments
 (0)