Skip to content

Commit

Permalink
chore(clerk-js): Revert passkey as preferred strategy for sign in (#3028
Browse files Browse the repository at this point in the history
)
  • Loading branch information
panteliselef authored Mar 22, 2024
1 parent abbd639 commit 63692bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .changeset/tough-rings-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 0 additions & 1 deletion packages/clerk-js/src/ui/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const getIdentifierControlDisplayValues = (
};

export const PREFERRED_SIGN_IN_STRATEGIES = Object.freeze({
Passkey: 'passkey',
Password: 'password',
OTP: 'otp',
});
Expand Down
19 changes: 10 additions & 9 deletions packages/clerk-js/src/ui/components/SignIn/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/displayConfig.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 63692bc

Please sign in to comment.