From e9e49babf891d680c82dba345694d58658ec56a2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 24 Oct 2024 13:35:29 -0700 Subject: [PATCH] enh: remove token cookie on signout --- .../open_webui/apps/webui/routers/auths.py | 6 +++++ src/lib/apis/auths/index.ts | 25 +++++++++++++++++++ .../components/layout/Sidebar/UserMenu.svelte | 4 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/apps/webui/routers/auths.py b/backend/open_webui/apps/webui/routers/auths.py index 35fd254f1..ef0a0d445 100644 --- a/backend/open_webui/apps/webui/routers/auths.py +++ b/backend/open_webui/apps/webui/routers/auths.py @@ -323,6 +323,12 @@ async def signup(request: Request, response: Response, form_data: SignupForm): raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err)) +@router.get("/signout") +async def signout(response: Response): + response.delete_cookie("token") + return {"status": True} + + ############################ # AddUser ############################ diff --git a/src/lib/apis/auths/index.ts b/src/lib/apis/auths/index.ts index 1bdb74694..30f21c302 100644 --- a/src/lib/apis/auths/index.ts +++ b/src/lib/apis/auths/index.ts @@ -180,6 +180,31 @@ export const userSignUp = async ( return res; }; +export const userSignOut = async () => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/auths/signout`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + }, + credentials: 'include' + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res; + }) + .catch((err) => { + console.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } +}; + export const addUser = async ( token: string, name: string, diff --git a/src/lib/components/layout/Sidebar/UserMenu.svelte b/src/lib/components/layout/Sidebar/UserMenu.svelte index caa5712d3..e56cb5efc 100644 --- a/src/lib/components/layout/Sidebar/UserMenu.svelte +++ b/src/lib/components/layout/Sidebar/UserMenu.svelte @@ -8,6 +8,7 @@ import { showSettings, activeUserCount, USAGE_POOL, mobile, showSidebar } from '$lib/stores'; import { fade, slide } from 'svelte/transition'; import Tooltip from '$lib/components/common/Tooltip.svelte'; + import { userSignOut } from '$lib/apis/auths'; const i18n = getContext('i18n'); @@ -154,7 +155,8 @@