Commit a2e74c59 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: auth error handling

parent 6a2c1600
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)
...@@ -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."
) )
......
...@@ -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"
/> />
......
<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`);
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment