mirror of
https://github.com/open-webui/open-webui
synced 2024-11-22 08:07:55 +00:00
feat: auth error handling
This commit is contained in:
parent
6a2c1600f5
commit
a2e74c59b9
@ -1,10 +1,12 @@
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
from pymongo import MongoClient
|
||||
from constants import ERROR_MESSAGES
|
||||
|
||||
from secrets import token_bytes
|
||||
from base64 import b64encode
|
||||
import os
|
||||
|
||||
|
||||
load_dotenv(find_dotenv())
|
||||
|
||||
####################################
|
||||
@ -35,23 +37,30 @@ WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.11")
|
||||
# WEBUI_AUTH
|
||||
####################################
|
||||
|
||||
|
||||
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")
|
||||
DB = DB_CLIENT["ollama-webui"]
|
||||
WEBUI_DB_URL = os.environ.get("WEBUI_DB_URL", "mongodb://root:root@localhost:27017/")
|
||||
|
||||
####################################
|
||||
# WEBUI_JWT_SECRET_KEY
|
||||
####################################
|
||||
if WEBUI_AUTH and WEBUI_DB_URL == "":
|
||||
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):
|
||||
def __str__(self) -> str:
|
||||
return super().__str__()
|
||||
|
||||
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 = (
|
||||
"Your session has expired or the token is invalid. Please sign in again."
|
||||
)
|
||||
|
@ -330,7 +330,7 @@
|
||||
/>
|
||||
{:else}
|
||||
<img
|
||||
src={$user.profile_image_url}
|
||||
src={$user ? $user.profile_image_url : '/user.png'}
|
||||
class=" max-w-[28px] object-cover rounded-full"
|
||||
alt="User profile"
|
||||
/>
|
||||
|
@ -1,6 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import fileSaver from 'file-saver';
|
||||
const { saveAs } = fileSaver;
|
||||
|
||||
import { goto, invalidateAll } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { user, db, chats, showSettings, chatId } from '$lib/stores';
|
||||
@ -141,7 +144,7 @@
|
||||
|
||||
const exportChatHistory = async () => {
|
||||
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`);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user