From 5b0f53e8270d62c084b0ed5e71d79b42d45b89f0 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 7 Oct 2026 15:40:44 +0400 Subject: [PATCH] refac --- src/lib/components/auth/MfaManagement.svelte | 78 +++++++++++++++++++ .../chat/Settings/Account/Mfa.svelte | 37 +++------ src/routes/+layout.svelte | 21 ++++- 3 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 src/lib/components/auth/MfaManagement.svelte diff --git a/src/lib/components/auth/MfaManagement.svelte b/src/lib/components/auth/MfaManagement.svelte new file mode 100644 index 0000000000..8595d60887 --- /dev/null +++ b/src/lib/components/auth/MfaManagement.svelte @@ -0,0 +1,78 @@ + + + + +
+
+ {#if 'challenge' in flow} + + {:else if codes.length} + + {:else if error} + + + {:else} +
+ + {$i18n.t('Loading...')} +
+ {/if} +
+
diff --git a/src/lib/components/chat/Settings/Account/Mfa.svelte b/src/lib/components/chat/Settings/Account/Mfa.svelte index db7334d7fb..d9d428a1ad 100644 --- a/src/lib/components/chat/Settings/Account/Mfa.svelte +++ b/src/lib/components/chat/Settings/Account/Mfa.svelte @@ -1,13 +1,11 @@
- {#if codes.length} -
- {:else if challenge} -
- { - challenge = null; - }} - /> -
- {:else if status} + {#if status}
{status.enabled diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 43dbde516b..4f0b5bb06e 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -79,6 +79,7 @@ import AppSidebar from '$lib/components/app/AppSidebar.svelte'; import SyncStatsModal from '$lib/components/chat/Settings/SyncStatsModal.svelte'; import Spinner from '$lib/components/common/Spinner.svelte'; + import MfaManagement from '$lib/components/auth/MfaManagement.svelte'; import { getOutputText } from '$lib/components/chat/Messages/structuredOutput'; import { getUserSettings } from '$lib/apis/users'; import dayjs from 'dayjs'; @@ -101,13 +102,22 @@ // handle frontend updates (https://svelte.dev/docs/kit/configuration#version) beforeNavigate(async ({ willUnload, to }) => { - if (updated.current && !willUnload && to?.url) { + if (updated.current && !mfaManagement && !willUnload && to?.url) { await unregisterServiceWorkers(); location.href = to.url.href; } }); setContext('i18n', i18n); + /** @type {import('$lib/components/auth/MfaManagement.svelte').MfaManagementFlow | null} */ + let mfaManagement = null; + setContext( + 'showMfaManagement', + /** @param {import('$lib/components/auth/MfaManagement.svelte').MfaManagementFlow} flow */ + (flow) => { + mfaManagement = flow; + } + ); const bc = new BroadcastChannel('active-tab-channel'); @@ -208,8 +218,9 @@ if (version !== null || deploymentId !== null) { if ( - ($WEBUI_VERSION !== null && version !== $WEBUI_VERSION) || - ($WEBUI_DEPLOYMENT_ID !== null && deploymentId !== $WEBUI_DEPLOYMENT_ID) + !mfaManagement && + (($WEBUI_VERSION !== null && version !== $WEBUI_VERSION) || + ($WEBUI_DEPLOYMENT_ID !== null && deploymentId !== $WEBUI_DEPLOYMENT_ID)) ) { await unregisterServiceWorkers(); location.href = location.href; @@ -1465,7 +1476,9 @@ {/if} {#if loaded} - {#if $isApp} + {#if mfaManagement} + (mfaManagement = null)} /> + {:else if $isApp}