Skip to content

Commit

Permalink
fix(types,elements,clerk-js): Update types to account for null second…
Browse files Browse the repository at this point in the history
… factors (#3780)
  • Loading branch information
dstaley authored Jul 23, 2024
1 parent 6a46425 commit 86c75e5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changeset/weak-pumpkins-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@clerk/clerk-js": patch
"@clerk/elements": patch
"@clerk/types": patch
---

Update types to account for null second factors
4 changes: 2 additions & 2 deletions packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SignIn extends BaseResource implements SignInResource {
status: SignInStatus | null = null;
supportedIdentifiers: SignInIdentifier[] = [];
supportedFirstFactors: SignInFirstFactor[] = [];
supportedSecondFactors: SignInSecondFactor[] = [];
supportedSecondFactors: SignInSecondFactor[] | null = null;
firstFactorVerification: VerificationResource = new Verification(null);
secondFactorVerification: VerificationResource = new Verification(null);
identifier: string | null = null;
Expand Down Expand Up @@ -339,7 +339,7 @@ export class SignIn extends BaseResource implements SignInResource {
this.supportedIdentifiers = data.supported_identifiers;
this.identifier = data.identifier;
this.supportedFirstFactors = deepSnakeToCamel(data.supported_first_factors) as SignInFirstFactor[];
this.supportedSecondFactors = deepSnakeToCamel(data.supported_second_factors) as SignInSecondFactor[];
this.supportedSecondFactors = deepSnakeToCamel(data.supported_second_factors) as SignInSecondFactor[] | null;
this.firstFactorVerification = new Verification(data.first_factor_verification);
this.secondFactorVerification = new Verification(data.second_factor_verification);
this.createdSessionId = data.created_session_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ const AlternativeMethodsList = (props: AlternativeMethodsProps & { onHavingTroub
gap={3}
>
<Col gap={2}>
{supportedSecondFactors.sort(backupCodePrefFactorComparator).map((factor, i) => (
<ArrowBlockButton
textLocalizationKey={getButtonLabel(factor)}
elementDescriptor={descriptors.alternativeMethodsBlockButton}
textElementDescriptor={descriptors.alternativeMethodsBlockButtonText}
arrowElementDescriptor={descriptors.alternativeMethodsBlockButtonArrow}
key={i}
isDisabled={card.isLoading}
onClick={() => onFactorSelected(factor)}
/>
))}
{supportedSecondFactors &&
supportedSecondFactors.sort(backupCodePrefFactorComparator).map((factor, i) => (
<ArrowBlockButton
textLocalizationKey={getButtonLabel(factor)}
elementDescriptor={descriptors.alternativeMethodsBlockButton}
textElementDescriptor={descriptors.alternativeMethodsBlockButtonText}
arrowElementDescriptor={descriptors.alternativeMethodsBlockButtonArrow}
key={i}
isDisabled={card.isLoading}
onClick={() => onFactorSelected(factor)}
/>
))}
</Col>
<Card.Action elementId='alternativeMethods'>
{onBackLinkClick && (
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/components/SignIn/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function factorHasLocalStrategy(factor: SignInFactor | undefined | null):
}

// The priority of second factors is: TOTP -> Phone code -> any other factor
export function determineStartingSignInSecondFactor(secondFactors: SignInFactor[]): SignInFactor | null {
export function determineStartingSignInSecondFactor(secondFactors: SignInFactor[] | null): SignInFactor | null {
if (!secondFactors || secondFactors.length === 0) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function determineStrategyWhenOTPIsPreferred(factors: SignInFirstFactor[], ident
}

// The priority of second factors is: TOTP -> Phone code -> any other factor
export function determineStartingSignInSecondFactor(secondFactors: SignInSecondFactor[]) {
export function determineStartingSignInSecondFactor(secondFactors: SignInSecondFactor[] | null) {
if (!secondFactors || secondFactors.length === 0) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/signIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface SignInResource extends ClerkResource {
*/
supportedIdentifiers: SignInIdentifier[];
supportedFirstFactors: SignInFirstFactor[];
supportedSecondFactors: SignInSecondFactor[];
supportedSecondFactors: SignInSecondFactor[] | null;
firstFactorVerification: VerificationResource;
secondFactorVerification: VerificationResource;
identifier: string | null;
Expand Down

0 comments on commit 86c75e5

Please sign in to comment.