diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 1caf156bfa..b080af7964 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -2347,8 +2347,14 @@ async def get_app_config(request: Request): status_code=status.HTTP_401_UNAUTHORIZED, detail='Invalid token', ) - if data is not None and 'id' in data and await is_valid_token(data, request.app.state.redis): - user = await Users.get_user_by_id(data['id']) + if data is not None and 'id' in data: + try: + if await is_valid_token(data, request.app.state.redis): + user = await Users.get_user_by_id(data['id']) + except HTTPException as e: + # A deleted or deactivated account gets the public config + if e.status_code != status.HTTP_401_UNAUTHORIZED: + raise group_defaults = None if user is not None and user.role in ('admin', 'user'): diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 698f5f27e6..bb3e6c15e6 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -1502,14 +1502,15 @@ export const getUsage = async (token: string = '') => { return res; }; -export const getBackendConfig = async () => { +export const getBackendConfig = async (token: string = '') => { let error = null; const res = await fetch(`${WEBUI_BASE_URL}/api/config`, { method: 'GET', credentials: 'include', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) } }) .then(async (res) => { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 138feff65c..2806712e50 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1340,9 +1340,12 @@ }; window.addEventListener('beforeunload', beforeUnloadHandler); + const sessionUserRequest = localStorage.token ? getSessionUser(localStorage.token) : null; + sessionUserRequest?.catch(() => {}); + let backendConfig = null; try { - backendConfig = await getBackendConfig(); + backendConfig = await getBackendConfig(localStorage.token); console.log('Backend config:', backendConfig); } catch (error) { if (error?.authRedirect) { @@ -1380,20 +1383,15 @@ if ($config) { await setupSocket($config.features?.enable_websocket ?? true); - if (localStorage.token) { + if (sessionUserRequest) { // Get Session User Info - const sessionUser = await getSessionUser(localStorage.token).catch((error) => { + const sessionUser = await sessionUserRequest.catch((error) => { toast.error(`${error}`); return null; }); if (sessionUser) { await user.set(sessionUser); - try { - await config.set(await getBackendConfig()); - } catch (error) { - console.error('Error refreshing backend config:', error); - } // Keep user timezone in sync on every app load/refresh const timezone = getUserTimezone();