From 63692bcf5563b92a4a1bb6619bda9967dc951a18 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 22 Mar 2024 02:20:44 +0200 Subject: [PATCH] chore(clerk-js): Revert passkey as preferred strategy for sign in (#3028) --- .changeset/tough-rings-rest.md | 2 ++ packages/clerk-js/src/ui/common/constants.ts | 1 - .../src/ui/components/SignIn/utils.ts | 19 ++++++++++--------- packages/types/src/displayConfig.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .changeset/tough-rings-rest.md diff --git a/.changeset/tough-rings-rest.md b/.changeset/tough-rings-rest.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/tough-rings-rest.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/clerk-js/src/ui/common/constants.ts b/packages/clerk-js/src/ui/common/constants.ts index ecd355a07c..37a7cf642b 100644 --- a/packages/clerk-js/src/ui/common/constants.ts +++ b/packages/clerk-js/src/ui/common/constants.ts @@ -72,7 +72,6 @@ export const getIdentifierControlDisplayValues = ( }; export const PREFERRED_SIGN_IN_STRATEGIES = Object.freeze({ - Passkey: 'passkey', Password: 'password', OTP: 'otp', }); diff --git a/packages/clerk-js/src/ui/components/SignIn/utils.ts b/packages/clerk-js/src/ui/components/SignIn/utils.ts index 162a053016..9799aa91da 100644 --- a/packages/clerk-js/src/ui/components/SignIn/utils.ts +++ b/packages/clerk-js/src/ui/components/SignIn/utils.ts @@ -56,10 +56,7 @@ const factorForIdentifier = (i: string | null) => (f: SignInFactor) => { return 'safeIdentifier' in f && f.safeIdentifier === i; }; -function determineStrategyWhenPasskeyIsPreferred( - factors: SignInFactor[], - identifier: string | null, -): SignInFactor | null { +function findPasskeyStrategy(factors: SignInFactor[]): SignInFactor | null { if (isWebAuthnSupported()) { // @ts-ignore const passkeyFactor = factors.find(({ strategy }) => strategy === 'passkey'); @@ -68,14 +65,17 @@ function determineStrategyWhenPasskeyIsPreferred( return passkeyFactor; } } - - return determineStrategyWhenOTPIsPreferred(factors, identifier); + return null; } function determineStrategyWhenPasswordIsPreferred( factors: SignInFactor[], identifier: string | null, ): SignInFactor | null { + const passkeyFactor = findPasskeyStrategy(factors); + if (passkeyFactor) { + return passkeyFactor; + } const selected = factors.sort(passwordPrefFactorComparator)[0]; if (selected.strategy === 'password') { return selected; @@ -84,6 +84,10 @@ function determineStrategyWhenPasswordIsPreferred( } function determineStrategyWhenOTPIsPreferred(factors: SignInFactor[], identifier: string | null): SignInFactor | null { + const passkeyFactor = findPasskeyStrategy(factors); + if (passkeyFactor) { + return passkeyFactor; + } const sortedBasedOnPrefFactor = factors.sort(otpPrefFactorComparator); const forIdentifier = sortedBasedOnPrefFactor.find(factorForIdentifier(identifier)); if (forIdentifier) { @@ -107,9 +111,6 @@ export function determineStartingSignInFactor( return null; } - if (preferredSignInStrategy === PREFERRED_SIGN_IN_STRATEGIES.Passkey) { - return determineStrategyWhenPasskeyIsPreferred(firstFactors, identifier); - } return preferredSignInStrategy === PREFERRED_SIGN_IN_STRATEGIES.Password ? determineStrategyWhenPasswordIsPreferred(firstFactors, identifier) : determineStrategyWhenOTPIsPreferred(firstFactors, identifier); diff --git a/packages/types/src/displayConfig.ts b/packages/types/src/displayConfig.ts index ded4d68089..36228251d0 100644 --- a/packages/types/src/displayConfig.ts +++ b/packages/types/src/displayConfig.ts @@ -1,7 +1,7 @@ import type { DisplayThemeJSON } from './json'; import type { ClerkResource } from './resource'; -export type PreferredSignInStrategy = 'passkey' | 'password' | 'otp'; +export type PreferredSignInStrategy = 'password' | 'otp'; export interface DisplayConfigJSON { object: 'display_config';