@@ -227,21 +227,31 @@ export class SignIn extends BaseResource implements SignInResource {
227227 public authenticateWithRedirect = async ( params : AuthenticateWithRedirectParams ) : Promise < void > => {
228228 const { strategy, redirectUrl, redirectUrlComplete, identifier } = params || { } ;
229229
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 ;
230+ /**
231+ * Covers the case of custom flows, where `authenticateWithRedirect` gets called
232+ * with a different identifier and the client already has a previous sign in attempty
233+ *
234+ * We shouldn't always create a fresh sign-in here since AIO components
235+ * currently perform this before `authenticateWithRedirect`
236+ */
237+ if ( this . id && identifier !== this . identifier ) {
238+ await this . create ( {
239+ strategy,
240+ identifier,
241+ redirectUrl : SignIn . clerk . buildUrlWithAuth ( redirectUrl ) ,
242+ actionCompleteRedirectUrl : redirectUrlComplete ,
243+ } ) ;
244+ }
245+
246+ if ( strategy === 'saml' || strategy === 'enterprise_sso' ) {
247+ await this . prepareFirstFactor ( {
248+ strategy,
249+ redirectUrl : SignIn . clerk . buildUrlWithAuth ( redirectUrl ) ,
250+ actionCompleteRedirectUrl : redirectUrlComplete ,
251+ } ) ;
252+ }
253+
254+ const { status, externalVerificationRedirectURL } = this . firstFactorVerification ;
245255
246256 if ( status === 'unverified' && externalVerificationRedirectURL ) {
247257 windowNavigate ( externalVerificationRedirectURL ) ;
0 commit comments