diff --git a/src/routes/(console)/account/updateEmail.svelte b/src/routes/(console)/account/updateEmail.svelte index f929cbecc..b5b12fba2 100644 --- a/src/routes/(console)/account/updateEmail.svelte +++ b/src/routes/(console)/account/updateEmail.svelte @@ -19,7 +19,7 @@ async function updateEmail() { try { await sdk.forConsole.account.updateEmail(email, emailPassword); - await invalidate(Dependencies.ACCOUNT); + await Promise.all([invalidate(Dependencies.ACCOUNT), invalidate(Dependencies.FACTORS)]); addNotification({ message: 'Email has been updated', type: 'success' diff --git a/src/routes/(console)/account/updateMfa.svelte b/src/routes/(console)/account/updateMfa.svelte index 220fea907..d945f8fb7 100644 --- a/src/routes/(console)/account/updateMfa.svelte +++ b/src/routes/(console)/account/updateMfa.svelte @@ -14,6 +14,8 @@ import type { Models } from '@appwrite.io/console'; import MfaRegenerateCodes from './mfaRegenerateCodes.svelte'; import { Pill } from '$lib/elements'; + import { page } from '$app/stores'; + import { onMount } from 'svelte'; let showSetup: boolean = false; let showDelete: boolean = false; @@ -26,6 +28,56 @@ .map(([factor, _]) => factor); $: enabledMethods = enabledFactors.filter((factor) => factor !== 'recoveryCode'); + $: cleanUrl = $page.url.origin + $page.url.pathname; + + let creatingVerification = false; + + async function createVerification() { + creatingVerification = true; + + try { + await sdk.forConsole.account.createVerification(cleanUrl); + addNotification({ + message: 'Verification email has been sent', + type: 'success' + }); + } catch (error) { + addNotification({ + message: error.message, + type: 'error' + }); + } finally { + creatingVerification = false; + } + } + + async function updateEmailVerification() { + const searchParams = $page.url.searchParams; + const userId = searchParams.get('userId'); + const secret = searchParams.get('secret'); + + history.replaceState(null, '', cleanUrl); + + if (userId && secret) { + try { + await sdk.forConsole.account.updateVerification(userId, secret); + addNotification({ + message: 'Email verified successfully', + type: 'success' + }); + await Promise.all([ + invalidate(Dependencies.ACCOUNT), + invalidate(Dependencies.FACTORS) + ]); + } catch (error) { + addNotification({ + message: error.message, + type: 'error' + }); + } + } + } + async function updateMfa() { try { await sdk.forConsole.account.updateMFA(!$user.mfa); @@ -77,6 +129,10 @@ $: if (!showRecoveryCodes) { codes = null; } + + onMount(() => { + updateEmailVerification(); + }); @@ -159,13 +215,34 @@ + {:else if !$user.emailVerification} +
+
+
+
+
+
+ Email + unverified +
+ Verify your email to receive login MFA codes. +
+
+ +
{/if} {#if $factors.phone}
-
+