From 8d5c3ee56ff68dbec81e6a8d0b2e5bb3a2505553 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 25 Dec 2023 22:14:06 -0800 Subject: [PATCH] feat: backend required error page --- backend/config.py | 6 ++--- src/routes/+layout.svelte | 25 ++++++++++++-------- src/routes/error/+page.svelte | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 src/routes/error/+page.svelte diff --git a/backend/config.py b/backend/config.py index e0014bd8..8e100fe5 100644 --- a/backend/config.py +++ b/backend/config.py @@ -31,13 +31,13 @@ if ENV == "prod": # WEBUI_VERSION #################################### -WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.40") +WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.42") #################################### -# WEBUI_AUTH +# WEBUI_AUTH (Required for security) #################################### -WEBUI_AUTH = True if os.environ.get("WEBUI_AUTH", "FALSE") == "TRUE" else False +WEBUI_AUTH = True #################################### # WEBUI_JWT_SECRET_KEY diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 7479f559..e19d5f37 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -11,7 +11,8 @@ let loaded = false; onMount(async () => { - const resBackend = await fetch(`${WEBUI_API_BASE_URL}/`, { + // Check Backend Status + const res = await fetch(`${WEBUI_API_BASE_URL}/`, { method: 'GET', headers: { 'Content-Type': 'application/json' @@ -26,13 +27,14 @@ return null; }); - console.log(resBackend); - await config.set(resBackend); + if (res) { + await config.set(res); + console.log(res); - if ($config) { - if ($config.auth) { + if ($config) { if (localStorage.token) { - const res = await fetch(`${WEBUI_API_BASE_URL}/auths`, { + // Get Session User Info + const sessionUser = await fetch(`${WEBUI_API_BASE_URL}/auths`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -49,8 +51,8 @@ return null; }); - if (res) { - await user.set(res); + if (sessionUser) { + await user.set(sessionUser); } else { localStorage.removeItem('token'); await goto('/auth'); @@ -59,6 +61,8 @@ await goto('/auth'); } } + } else { + await goto(`/error`); } await tick(); @@ -69,8 +73,9 @@ Ollama - -{#if $config !== undefined && loaded} +{#if loaded} {/if} + + diff --git a/src/routes/error/+page.svelte b/src/routes/error/+page.svelte new file mode 100644 index 00000000..5ce3fa03 --- /dev/null +++ b/src/routes/error/+page.svelte @@ -0,0 +1,44 @@ + + +{#if loaded} +
+
+
+
+
Ollama WebUI Backend Required
+ +
+ Oops! It seems like your Ollama WebUI needs a little attention. + describe troubleshooting/installation, help @ discord + + +
+ +
+ +
+
+
+
+
+{/if}