diff --git a/.changeset/twenty-maps-train.md b/.changeset/twenty-maps-train.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/twenty-maps-train.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx index 5e325281cc4..cdc4a70e962 100644 --- a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx +++ b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx @@ -1,6 +1,6 @@ import { useClerk } from '@clerk/shared/react'; import { isWebAuthnAutofillSupported, isWebAuthnSupported } from '@clerk/shared/webauthn'; -import type { ClerkAPIError, SignInCreateParams } from '@clerk/types'; +import type { ClerkAPIError, SignInCreateParams, SignInResource } from '@clerk/types'; import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import { ERROR_CODES } from '../../../core/constants'; @@ -245,18 +245,28 @@ export function _SignInStart(): JSX.Element { } as SignInCreateParams; }; + const safePasswordSignInForSamlInstance = ( + signInCreatePromise: Promise, + fields: Array>, + ) => { + return signInCreatePromise.then(signInResource => { + if (!userSettings.saml.enabled) { + return signInResource; + } + /** + * For SAML enabled instances, perform sign in with password only when it is allowed for the identified user. + */ + const passwordField = fields.find(f => f.name === 'password')?.value; + if (!passwordField || signInResource.supportedFirstFactors.some(ff => ff.strategy === 'saml')) { + return signInResource; + } + return signInResource.attemptFirstFactor({ strategy: 'password', password: passwordField }); + }); + }; + const signInWithFields = async (...fields: Array>) => { try { - const res = await signIn.create(buildSignInParams(fields)).then(signInResource => { - /** - * For SAML enabled instances, perform sign in with password only when it is allowed for the identified user. - */ - const passwordField = fields.find(f => f.name === 'password')?.value; - if (!passwordField || signInResource.supportedFirstFactors.some(ff => ff.strategy === 'saml')) { - return signInResource; - } - return signInResource.attemptFirstFactor({ strategy: 'password', password: passwordField }); - }); + const res = await safePasswordSignInForSamlInstance(signIn.create(buildSignInParams(fields)), fields); switch (res.status) { case 'needs_identifier': diff --git a/packages/clerk-js/src/ui/utils/test/fixtures.ts b/packages/clerk-js/src/ui/utils/test/fixtures.ts index d32051038b7..d7291bc825d 100644 --- a/packages/clerk-js/src/ui/utils/test/fixtures.ts +++ b/packages/clerk-js/src/ui/utils/test/fixtures.ts @@ -178,6 +178,7 @@ const createBaseUserSettings = (): UserSettingsJSON => { attributes: { ...attributeConfig }, actions: { delete_self: false, create_organization: false }, social: { ...socialConfig }, + saml: { enabled: false }, sign_in: { second_factor: { required: false,