From 859a0d56fcb0edbe11e707301d1b64c31ebcb225 Mon Sep 17 00:00:00 2001
From: Bradley Schofield
Date: Fri, 5 Jul 2024 17:06:12 +0900
Subject: [PATCH] Run Linter and svelte-check
---
.../components/mfaChallengeFormList.svelte | 160 ++++++++-----
src/lib/sdk/account.ts | 37 ++-
src/lib/stores/sdk.ts | 2 +-
.../console/account/deleteWebauthn.svelte | 213 +++++++++---------
src/routes/console/account/updateMfa.svelte | 54 ++---
src/routes/console/account/webauthnMfa.svelte | 6 +-
6 files changed, 256 insertions(+), 216 deletions(-)
diff --git a/src/lib/components/mfaChallengeFormList.svelte b/src/lib/components/mfaChallengeFormList.svelte
index 02f06171a..604c2d7f7 100644
--- a/src/lib/components/mfaChallengeFormList.svelte
+++ b/src/lib/components/mfaChallengeFormList.svelte
@@ -7,7 +7,7 @@
);
}
- if (code = 'webauthn') {
+ if ((code = 'webauthn')) {
await sdk.forConsole.webauthnAccount.createMfaWebauthnChallengeHelper();
} else {
await sdk.forConsole.account.updateMfaChallenge(challenge.$id, code);
@@ -72,69 +72,111 @@
Enter below one of the recovery codes you received when enabling MFA for this account.
+ {:else if !factors.webauthn}
+ {#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}
+
{:else}
- {#if !factors.webauthn}
- {#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}
-
- {:else}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Insert your security key into your device and press authenticate.
-
- Authenticate
- {/if}
+
+ Authenticate
{/if}
{#if showVerifyButton}
diff --git a/src/lib/sdk/account.ts b/src/lib/sdk/account.ts
index a5197270c..0c3474a39 100644
--- a/src/lib/sdk/account.ts
+++ b/src/lib/sdk/account.ts
@@ -1,4 +1,4 @@
-import type { Client, Models } from '@appwrite.io/console';
+import type { Client } from '@appwrite.io/console';
import { startRegistration, startAuthentication } from '@simplewebauthn/browser';
export type WebauthnRegisterChallenge = {
@@ -8,16 +8,16 @@ export type WebauthnRegisterChallenge = {
id: string;
name: string;
icon: string;
- },
+ };
user: {
id: string;
name: string;
displayName: string;
- },
+ };
challenge: string;
pubKeyCredParams: any;
timeout: number;
-}
+};
export class Account {
client: Client;
@@ -30,13 +30,9 @@ export class Account {
const path = '/account/mfa/authenticators/webauthn';
const uri = new URL(this.client.config.endpoint + path);
- return await this.client.call(
- 'POST',
- uri,
- {
- 'content-type': 'application/json'
- },
- );
+ return await this.client.call('POST', uri, {
+ 'content-type': 'application/json'
+ });
}
async completeWebauthnMfaAuthenticator(credential: Credential) {
@@ -68,13 +64,9 @@ export class Account {
const path = '/account/mfa/challenge/webauthn';
const uri = new URL(this.client.config.endpoint + path);
- return await this.client.call(
- 'POST',
- uri,
- {
- 'content-type': 'application/json'
- },
- );
+ return await this.client.call('POST', uri, {
+ 'content-type': 'application/json'
+ });
}
async completeMfaWebauthnChallenge(challengeId: string, credential: Credential) {
@@ -103,7 +95,11 @@ export class Account {
await this.completeMfaWebauthnChallenge(challenge.$id, credential);
}
- async deleteMfaWebauthnAuthenticator(challengeId?: string, credential?: Credential, recoveryKey?: string) {
+ async deleteMfaWebauthnAuthenticator(
+ challengeId?: string,
+ credential?: Credential,
+ recoveryKey?: string
+ ) {
const path = '/account/mfa/authenticator/webauthn';
const uri = new URL(this.client.config.endpoint + path);
@@ -132,7 +128,6 @@ export class Account {
);
}
-
async deleteMfaWebauthnAuthenticatorHelper() {
let challenge = await this.createMfaWebauthnChallenge();
@@ -140,4 +135,4 @@ export class Account {
await this.deleteMfaWebauthnAuthenticator(challenge.$id, credential);
}
-}
\ No newline at end of file
+}
diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts
index d497dbbe2..8434b9e99 100644
--- a/src/lib/stores/sdk.ts
+++ b/src/lib/stores/sdk.ts
@@ -23,7 +23,7 @@ import {
} from '@appwrite.io/console';
import { Billing } from '../sdk/billing';
import { Sources } from '$lib/sdk/sources';
-import { Account as WebauthnAccount } from '$lib/sdk/account'
+import { Account as WebauthnAccount } from '$lib/sdk/account';
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
diff --git a/src/routes/console/account/deleteWebauthn.svelte b/src/routes/console/account/deleteWebauthn.svelte
index 7848b3e27..75cf390be 100644
--- a/src/routes/console/account/deleteWebauthn.svelte
+++ b/src/routes/console/account/deleteWebauthn.svelte
@@ -5,7 +5,6 @@
import { Dependencies } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import FormList from '$lib/elements/forms/formList.svelte';
- import InputDigits from '$lib/elements/forms/inputDigits.svelte';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
@@ -18,7 +17,11 @@
async function deleteWebauthnAuthenticator() {
if (step === 2) {
try {
- await sdk.forConsole.webauthnAccount.deleteMfaWebauthnAuthenticator(null, null, code);
+ await sdk.forConsole.webauthnAccount.deleteMfaWebauthnAuthenticator(
+ null,
+ null,
+ code
+ );
await invalidate(Dependencies.ACCOUNT);
await invalidate(Dependencies.FACTORS);
showWebauthnDelete = false;
@@ -65,118 +68,118 @@
bind:error
headerDivider={false}>
{#if step == 1}
- Please authenticate with your Webauthn Device to finish deletion.
-
-
-
-
-
-
-
+ Please authenticate with your Webauthn Device to finish deletion.
+
-
-
-
+ d="M64.3407 52.8467H61.6366H64.3407ZM67.0448 63.801V52.8467H61.6366V63.801H67.0448ZM67.0448 52.8467C67.0448 50.0024 68.2632 47.2283 70.5093 45.1486L66.8349 41.1802C63.5343 44.2363 61.6366 48.4278 61.6366 52.8467L67.0448 52.8467ZM70.5093 45.1486C72.7624 43.0624 75.8598 41.858 79.129 41.858V36.4497C74.554 36.4497 70.1285 38.1305 66.8349 41.1802L70.5093 45.1486ZM79.129 41.858C82.3982 41.858 85.4956 43.0624 87.7487 45.1486L91.4231 41.1802C88.1295 38.1305 83.704 36.4497 79.129 36.4497V41.858ZM87.7487 45.1486C89.9948 47.2283 91.2132 50.0024 91.2132 52.8467H96.6215C96.6215 48.4278 94.7238 44.2363 91.4231 41.1802L87.7487 45.1486ZM91.2132 52.8467V63.801H96.6215V52.8467H91.2132Z"
+ fill="#E4E4E7"
+ mask="url(#path-3-inside-1_6_2371)" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ d="M52.2909 65.1529H105.967C109.159 65.1529 112.283 68.6256 112.283 73.6597V108.166C112.283 113.2 109.159 116.672 105.967 116.672H52.2909C49.0993 116.672 45.975 113.2 45.975 108.166V73.6597C45.975 68.6256 49.0993 65.1529 52.2909 65.1529Z"
+ stroke="#E4E4E7"
+ stroke-width="2.70415" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{:else if step == 2}
- Enter your recovery code to finish deletion.
-
-
-
+ Enter your recovery code to finish deletion.
+
+
+
{/if}
(showWebauthnDelete = false)}>Cancel
-
+
{#if step == 1}
- (step = 2)}>Use a recovery code
- Authenticate
+ (step = 2)}>Use a recovery code
+ Authenticate
{:else if step == 2}
- (step = 1)}>Back
- Delete
+ (step = 1)}>Back
+ Delete
{/if}
diff --git a/src/routes/console/account/updateMfa.svelte b/src/routes/console/account/updateMfa.svelte
index 2353b987c..2cf286c37 100644
--- a/src/routes/console/account/updateMfa.svelte
+++ b/src/routes/console/account/updateMfa.svelte
@@ -141,39 +141,39 @@
-
-
-
+ class="method u-flex u-flex-vertical-mobile u-gap-16 u-main-space-between u-sep-block-end"
+ style="padding-block-end: 16px">
+
+
+
+
+
+ Webauthn
+ {#if $factors.webauthn}
+ A webauthn key has been added to this account.
+ {:else}
+ Use a security key to provide two-factor for your account.
+ {/if}
+
-
-
Webauthn
+
{#if $factors.webauthn}
- A webauthn key has been added to this account.
+ (showWebauthnDelete = true)}>Delete
+ (showWebauthnDelete = true)}>Delete
{:else}
- Use a security key to provide two-factor for your account.
+ (showWebauthnSetup = true)}
+ >Add
{/if}
-
- {#if $factors.webauthn}
- (showWebauthnDelete = true)}>Delete
- (showWebauthnDelete = true)}>Delete
- {:else}
- (showWebauthnSetup = true)}>Add
- {/if}
-
-
{#if $factors.email}
Follow the instructions provided by your browser to register a new security key.
{#await addAuthenticator()}
-
+
{/await}
{:else if step === 2}
{#if !error}