Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
a2e74c59
Commit
a2e74c59
authored
Nov 20, 2023
by
Timothy J. Baek
Browse files
feat: auth error handling
parent
6a2c1600
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
15 deletions
+31
-15
backend/config.py
backend/config.py
+22
-13
backend/constants.py
backend/constants.py
+4
-0
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+1
-1
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+4
-1
No files found.
backend/config.py
View file @
a2e74c59
from
dotenv
import
load_dotenv
,
find_dotenv
from
dotenv
import
load_dotenv
,
find_dotenv
from
pymongo
import
MongoClient
from
pymongo
import
MongoClient
from
constants
import
ERROR_MESSAGES
from
secrets
import
token_bytes
from
secrets
import
token_bytes
from
base64
import
b64encode
from
base64
import
b64encode
import
os
import
os
load_dotenv
(
find_dotenv
())
load_dotenv
(
find_dotenv
())
####################################
####################################
...
@@ -35,23 +37,30 @@ WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.11")
...
@@ -35,23 +37,30 @@ WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.11")
# WEBUI_AUTH
# WEBUI_AUTH
####################################
####################################
WEBUI_AUTH
=
True
if
os
.
environ
.
get
(
"WEBUI_AUTH"
,
"TRUE"
)
==
"TRUE"
else
False
WEBUI_AUTH
=
True
if
os
.
environ
.
get
(
"WEBUI_AUTH"
,
"TRUE"
)
==
"TRUE"
else
False
if
WEBUI_AUTH
:
####################################
####################################
# WEBUI_DB
# WEBUI_DB
####################################
####################################
WEBUI_DB_URL
=
os
.
environ
.
get
(
"WEBUI_DB_URL"
,
"mongodb://root:root@localhost:27017/"
)
WEBUI_DB_URL
=
os
.
environ
.
get
(
if
WEBUI_AUTH
and
WEBUI_DB_URL
==
""
:
"WEBUI_DB_URL"
,
"mongodb://root:root@localhost:27017/"
raise
ValueError
(
ERROR_MESSAGES
.
ENV_VAR_NOT_FOUND
)
)
DB_CLIENT
=
MongoClient
(
f
"
{
WEBUI_DB_URL
}
?authSource=admin"
)
DB
=
DB_CLIENT
[
"ollama-webui"
]
####################################
DB_CLIENT
=
MongoClient
(
f
"
{
WEBUI_DB_URL
}
?authSource=admin"
)
# WEBUI_JWT_SECRET_KEY
DB
=
DB_CLIENT
[
"ollama-webui"
]
####################################
####################################
# WEBUI_JWT_SECRET_KEY
####################################
WEBUI_JWT_SECRET_KEY
=
os
.
environ
.
get
(
"WEBUI_JWT_SECRET_KEY"
,
"t0p-s3cr3t"
)
WEBUI_JWT_SECRET_KEY
=
os
.
environ
.
get
(
"WEBUI_JWT_SECRET_KEY"
,
"t0p-s3cr3t"
)
if
WEBUI_AUTH
and
WEBUI_JWT_SECRET_KEY
==
""
:
raise
ValueError
(
ERROR_MESSAGES
.
ENV_VAR_NOT_FOUND
)
backend/constants.py
View file @
a2e74c59
...
@@ -6,7 +6,11 @@ class MESSAGES(str, Enum):
...
@@ -6,7 +6,11 @@ class MESSAGES(str, Enum):
class
ERROR_MESSAGES
(
str
,
Enum
):
class
ERROR_MESSAGES
(
str
,
Enum
):
def
__str__
(
self
)
->
str
:
return
super
().
__str__
()
DEFAULT
=
lambda
err
=
""
:
f
"Something went wrong :/
\n
{
err
if
err
else
''
}
"
DEFAULT
=
lambda
err
=
""
:
f
"Something went wrong :/
\n
{
err
if
err
else
''
}
"
ENV_VAR_NOT_FOUND
=
"Essential environment variable not found. Terminating now."
INVALID_TOKEN
=
(
INVALID_TOKEN
=
(
"Your session has expired or the token is invalid. Please sign in again."
"Your session has expired or the token is invalid. Please sign in again."
)
)
...
...
src/lib/components/chat/Messages.svelte
View file @
a2e74c59
...
@@ -330,7 +330,7 @@
...
@@ -330,7 +330,7 @@
/>
/>
{:else}
{:else}
<img
<img
src=
{$user.profile_image_url}
src=
{$user
?
$
user
.profile_image_url
:
'/
user.png
'
}
class=
" max-w-[28px] object-cover rounded-full"
class=
" max-w-[28px] object-cover rounded-full"
alt=
"User profile"
alt=
"User profile"
/>
/>
...
...
src/lib/components/layout/Sidebar.svelte
View file @
a2e74c59
<script lang="ts">
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
import { goto, invalidateAll } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { page } from '$app/stores';
import { page } from '$app/stores';
import { user, db, chats, showSettings, chatId } from '$lib/stores';
import { user, db, chats, showSettings, chatId } from '$lib/stores';
...
@@ -141,7 +144,7 @@
...
@@ -141,7 +144,7 @@
const exportChatHistory = async () => {
const exportChatHistory = async () => {
await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
await chats.set(await $db.getAllFromIndex('chats', 'timestamp'));
let blob = new Blob([JSON.stringify(chats)], { type: 'application/json' });
let blob = new Blob([JSON.stringify(
$
chats)], { type: 'application/json' });
saveAs(blob, `chat-export-${Date.now()}.json`);
saveAs(blob, `chat-export-${Date.now()}.json`);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment