From 401c1949a04dfd1bcc3c8b9a4f77b73beb78b818 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 9 Jan 2026 18:51:38 +0400 Subject: [PATCH] refac --- backend/open_webui/routers/auths.py | 26 ++++++++++++++++++++++++++ src/lib/apis/auths/index.ts | 13 +++++++++++++ src/routes/auth/+page.svelte | 10 ++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 32e62526fc..30d4ebe4cc 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -189,6 +189,32 @@ async def update_profile( raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED) +############################ +# Update Timezone +############################ + + +class UpdateTimezoneForm(BaseModel): + timezone: str + + +@router.post("/update/timezone") +async def update_timezone( + form_data: UpdateTimezoneForm, + session_user=Depends(get_current_user), + db: Session = Depends(get_session), +): + if session_user: + Users.update_user_by_id( + session_user.id, + {"timezone": form_data.timezone}, + db=db, + ) + return {"status": True} + else: + raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED) + + ############################ # Update Password ############################ diff --git a/src/lib/apis/auths/index.ts b/src/lib/apis/auths/index.ts index 5450479af5..1fd22494b5 100644 --- a/src/lib/apis/auths/index.ts +++ b/src/lib/apis/auths/index.ts @@ -423,6 +423,19 @@ export const updateUserProfile = async (token: string, profile: object) => { return res; }; +export const updateUserTimezone = async (token: string, timezone: string) => { + await fetch(`${WEBUI_API_BASE_URL}/auths/update/timezone`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(token && { authorization: `Bearer ${token}` }) + }, + body: JSON.stringify({ timezone }) + }).catch((err) => { + console.error('Failed to update timezone:', err); + }); +}; + export const updateUserPassword = async (token: string, password: string, newPassword: string) => { let error = null; diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index 727c104100..660a7b3a72 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -9,12 +9,12 @@ import { page } from '$app/stores'; import { getBackendConfig } from '$lib/apis'; - import { ldapUserSignIn, getSessionUser, userSignIn, userSignUp } from '$lib/apis/auths'; + import { ldapUserSignIn, getSessionUser, userSignIn, userSignUp, updateUserTimezone } from '$lib/apis/auths'; import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants'; import { WEBUI_NAME, config, user, socket } from '$lib/stores'; - import { generateInitialsImage, canvasPixelTest } from '$lib/utils'; + import { generateInitialsImage, canvasPixelTest, getUserTimezone } from '$lib/utils'; import Spinner from '$lib/components/common/Spinner.svelte'; import OnBoarding from '$lib/components/OnBoarding.svelte'; @@ -47,6 +47,12 @@ await user.set(sessionUser); await config.set(await getBackendConfig()); + // Update user timezone + const timezone = getUserTimezone(); + if (sessionUser.token && timezone) { + updateUserTimezone(sessionUser.token, timezone); + } + if (!redirectPath) { redirectPath = $page.url.searchParams.get('redirect') || '/'; }