From b4cd503a027257ca42b57d7c68cf0d5f6844421f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 15 Oct 2024 02:51:08 -0700 Subject: [PATCH] refac --- backend/open_webui/apps/webui/routers/auths.py | 18 ++++++++++++------ backend/open_webui/utils/utils.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/apps/webui/routers/auths.py b/backend/open_webui/apps/webui/routers/auths.py index e9103f1d6..35fd254f1 100644 --- a/backend/open_webui/apps/webui/routers/auths.py +++ b/backend/open_webui/apps/webui/routers/auths.py @@ -64,8 +64,10 @@ async def get_session_user( expires_delta=expires_delta, ) - datetime_expires_at = datetime.datetime.fromtimestamp( - expires_at, datetime.timezone.utc + datetime_expires_at = ( + datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc) + if expires_at + else None ) # Set the cookie token @@ -193,8 +195,10 @@ async def signin(request: Request, response: Response, form_data: SigninForm): expires_delta=expires_delta, ) - datetime_expires_at = datetime.datetime.fromtimestamp( - expires_at, datetime.timezone.utc + datetime_expires_at = ( + datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc) + if expires_at + else None ) # Set the cookie token @@ -276,8 +280,10 @@ async def signup(request: Request, response: Response, form_data: SignupForm): expires_delta=expires_delta, ) - datetime_expires_at = datetime.datetime.fromtimestamp( - expires_at, datetime.timezone.utc + datetime_expires_at = ( + datetime.datetime.fromtimestamp(expires_at, datetime.timezone.utc) + if expires_at + else None ) # Set the cookie token diff --git a/backend/open_webui/utils/utils.py b/backend/open_webui/utils/utils.py index b744ab164..e087cb48f 100644 --- a/backend/open_webui/utils/utils.py +++ b/backend/open_webui/utils/utils.py @@ -104,7 +104,7 @@ def get_current_user( Users.update_user_last_active_by_id(user.id) return user else: - response.delete_cookie("token") + response.set_cookie("token", "", expires=0) raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED,