forked from open-webui/open-webui
feat: auth error handling
This commit is contained in:
parent
6a2c1600f5
commit
a2e74c59b9
4 changed files with 31 additions and 15 deletions
|
@ -1,10 +1,12 @@
|
||||||
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")
|
||||||
# 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/"
|
|
||||||
)
|
|
||||||
|
|
||||||
DB_CLIENT = MongoClient(f"{WEBUI_DB_URL}?authSource=admin")
|
WEBUI_DB_URL = os.environ.get("WEBUI_DB_URL", "mongodb://root:root@localhost:27017/")
|
||||||
DB = DB_CLIENT["ollama-webui"]
|
|
||||||
|
|
||||||
####################################
|
if WEBUI_AUTH and WEBUI_DB_URL == "":
|
||||||
# WEBUI_JWT_SECRET_KEY
|
raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
|
||||||
####################################
|
|
||||||
|
|
||||||
WEBUI_JWT_SECRET_KEY = os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t")
|
|
||||||
|
DB_CLIENT = MongoClient(f"{WEBUI_DB_URL}?authSource=admin")
|
||||||
|
DB = DB_CLIENT["ollama-webui"]
|
||||||
|
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# WEBUI_JWT_SECRET_KEY
|
||||||
|
####################################
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -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."
|
||||||
)
|
)
|
||||||
|
|
|
@ -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"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<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 @@
|
||||||
|
|
||||||
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`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue