From 547682c6741a143bcb0af435e199b4dcea7de530 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 5 Nov 2024 20:47:23 -0800 Subject: [PATCH] refac --- backend/open_webui/main.py | 5 +++-- src/routes/auth/+page.svelte | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index c0650e444..d06220692 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2216,16 +2216,17 @@ async def get_app_config(request: Request): if data is not None and "id" in data: user = Users.get_user_by_id(data["id"]) - user_count = 0 + onboarding = False if user is None: user_count = Users.get_num_users() + onboarding = user_count == 0 return { + **({"onboarding": True} if onboarding else {}), "status": True, "name": WEBUI_NAME, "version": VERSION, "default_locale": str(DEFAULT_LOCALE), - **({"onboarding": True} if user_count is 0 else {}), "oauth": { "providers": { name: config.get("name", name) diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index 96a6cd1ee..f40307816 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -27,7 +27,6 @@ let password = ''; let ldapUsername = ''; - let ldapPassword = ''; const setSessionUser = async (sessionUser) => { if (sessionUser) { @@ -64,6 +63,14 @@ await setSessionUser(sessionUser); }; + const ldapSignInHandler = async () => { + const sessionUser = await ldapUserSignIn(ldapUsername, password).catch((error) => { + toast.error(error); + return null; + }); + await setSessionUser(sessionUser); + }; + const submitHandler = async () => { if (mode === 'ldap') { await ldapSignInHandler(); @@ -74,14 +81,6 @@ } }; - const ldapSignInHandler = async () => { - const sessionUser = await ldapUserSignIn(ldapUsername, ldapPassword).catch((error) => { - toast.error(error); - return null; - }); - await setSessionUser(sessionUser); - }; - const checkOauthCallback = async () => { if (!$page.url.hash) { return; @@ -113,6 +112,7 @@ await goto('/'); } await checkOauthCallback(); + loaded = true; if (($config?.features.auth_trusted_header ?? false) || $config?.features.auth === false) { await signInHandler(); @@ -175,7 +175,8 @@
{ + on:submit={(e) => { + e.preventDefault(); submitHandler(); }} > @@ -265,9 +266,7 @@ class="bg-gray-700/5 hover:bg-gray-700/10 dark:bg-gray-100/5 dark:hover:bg-gray-100/10 dark:text-gray-300 dark:hover:text-white transition w-full rounded-full font-medium text-sm py-2.5" type="submit" > - {($config?.onboarding ?? false) - ? $i18n.t('Authenticate as Admin') - : $i18n.t('Authenticate')} + {$i18n.t('Authenticate')} {:else}