diff --git a/src/lib/components/index.ts b/src/lib/components/index.ts index 685b34d638..da5859ab45 100644 --- a/src/lib/components/index.ts +++ b/src/lib/components/index.ts @@ -73,3 +73,4 @@ export { default as RadioBoxes } from './radioBoxes.svelte'; export { default as ModalWrapper } from './modalWrapper.svelte'; export { default as ModalSideCol } from './modalSideCol.svelte'; export { default as ImagePreview } from './imagePreview.svelte'; +export { default as MfaChallengeFormList } from './mfaChallengeFormList.svelte'; diff --git a/src/lib/components/mfaChallengeFormList.svelte b/src/lib/components/mfaChallengeFormList.svelte new file mode 100644 index 0000000000..96e77daf21 --- /dev/null +++ b/src/lib/components/mfaChallengeFormList.svelte @@ -0,0 +1,134 @@ + + + + + + {#if challengeType == AuthenticationFactor.Recoverycode} +

+ Enter below one of the recovery codes you received when enabling MFA for this account. +

+ + {:else} + {#if factors.totp && (challengeType == AuthenticationFactor.Totp || challengeType == null)} +

Enter below a 6-digit one-time code generated by your authentication app.

+ {:else if challengeType == AuthenticationFactor.Email} +

A 6-digit verification code was sent to your email, enter it below.

+ {:else if challengeType == AuthenticationFactor.Phone} +

A 6-digit verification code was sent to your phone, enter it below.

+ {/if} + + {/if} + {#if showVerifyButton} + + + + {/if} + {#if enabledFactors.length > 1} + or +
+ {#if factors.totp && challengeType != null && challengeType != AuthenticationFactor.Totp} + + + + {/if} + {#if factors.email && challengeType != AuthenticationFactor.Email} + + + + {/if} + {#if factors.phone && challengeType != AuthenticationFactor.Phone} + + + + {/if} + {#if factors.recoveryCode && challengeType != AuthenticationFactor.Recoverycode} + + + + {/if} +
+ {/if} +
diff --git a/src/lib/elements/forms/inputDigits.svelte b/src/lib/elements/forms/inputDigits.svelte index 0610df78fb..c822d50bbb 100644 --- a/src/lib/elements/forms/inputDigits.svelte +++ b/src/lib/elements/forms/inputDigits.svelte @@ -24,7 +24,11 @@ onValueChange: ({ next }) => { value = next.join(''); - if (autoSubmit && value.length === length && !autoSubmitted) { + if (value.length < length) { + autoSubmitted = false; + } + + if (element && autoSubmit && value.length === length && !autoSubmitted) { autoSubmitted = true; const firstInputElement = element.querySelector('input'); firstInputElement?.form.requestSubmit(); diff --git a/src/lib/layout/header.svelte b/src/lib/layout/header.svelte index 16c97001a4..da82156371 100644 --- a/src/lib/layout/header.svelte +++ b/src/lib/layout/header.svelte @@ -1,5 +1,5 @@

Are you sure you want to regenerate all recovery codes? All previously generated recovery codes will become invalid.

-

Enter the 6-digit verification code generated by your authenticator app to continue.

- - - + diff --git a/src/routes/console/account/updateMfa.svelte b/src/routes/console/account/updateMfa.svelte index e15dc392ca..a257865f65 100644 --- a/src/routes/console/account/updateMfa.svelte +++ b/src/routes/console/account/updateMfa.svelte @@ -20,10 +20,19 @@ let showRegenerateRecoveryCodes = false; let codes: Models.MfaRecoveryCodes = null; + $: enabledFactors = Object.entries($factors) + .filter(([_, enabled]) => enabled) + .map(([factor, _]) => factor); + $: enabledMethods = enabledFactors.filter((factor) => factor !== 'recoveryCode'); + async function updateMfa() { try { await sdk.forConsole.account.updateMFA(!$user.mfa); await invalidate(Dependencies.ACCOUNT); + addNotification({ + message: `Multi-factor authentication has been ${$user.mfa ? 'enabled' : 'disabled'}`, + type: 'success' + }); trackEvent(Submit.AccountUpdateMfa, { mfa: !$user.mfa }); } catch (error) { addNotification({ @@ -63,6 +72,10 @@ trackError(error, Submit.AccountRecoveryCodesUpdate); } } + + $: if (!showRecoveryCodes) { + codes = null; + } @@ -87,99 +100,119 @@ href="https://appwrite.io/docs/products/auth/mfa">Learn more.

-
-
- Methods -
-
-
-
-
-
- Authenticator app - Use an authentication app to generate two-factor authentication - codes. -
+ {#if $user.mfa} +
+
+ Methods
-
- {#if $factors.totp} - - {:else} - - {/if} -
-
- - {#if $factors.email}
-
- Email verification - One-time codes will be sent to: {$user.email} + Authenticator app + Use an authentication app to generate two-factor authentication + codes.
+
+ {#if $factors.totp} + + + {:else} + + {/if} +
- {/if} - {#if $factors.phone} -
-
-
-
-
- SMS verification - One-time codes will be sent to: {$user.phone} + {#if $factors.email} +
+
+
+
+
+ Email verification + One-time codes will be sent to: {$user.email} +
-
- {/if} -
+ {/if} -
-
- Recovery + {#if $factors.phone} +
+
+
+
+
+ SMS verification + One-time codes will be sent to: {$user.phone} +
+
+
+ {/if}
-
-
-
-
+ {/if} + {/if}
@@ -190,7 +223,10 @@ - +