Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/twenty-maps-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a commit with a changeset :) and we have not released yet.

32 changes: 21 additions & 11 deletions packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -245,18 +245,28 @@ export function _SignInStart(): JSX.Element {
} as SignInCreateParams;
};

const safePasswordSignInForSamlInstance = (
signInCreatePromise: Promise<SignInResource>,
fields: Array<FormControlState<string>>,
) => {
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<FormControlState<string>>) => {
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':
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/utils/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down