Skip to content

Commit 76891f4

Browse files
committed
feat: update get_current_user to refresh last active timestamp asynchronously
1 parent 6fedd72 commit 76891f4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

backend/open_webui/utils/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from open_webui.constants import ERROR_MESSAGES
1717
from open_webui.env import WEBUI_SECRET_KEY, TRUSTED_SIGNATURE_KEY, STATIC_DIR
1818

19-
from fastapi import Depends, HTTPException, Request, Response, status
19+
from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status
2020
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
2121
from passlib.context import CryptContext
2222

@@ -142,6 +142,7 @@ def get_http_authorization_cred(auth_header: str):
142142

143143
def get_current_user(
144144
request: Request,
145+
background_tasks: BackgroundTasks,
145146
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
146147
):
147148
token = None
@@ -194,7 +195,9 @@ def get_current_user(
194195
detail=ERROR_MESSAGES.INVALID_TOKEN,
195196
)
196197
else:
197-
Users.update_user_last_active_by_id(user.id)
198+
# Refresh the user's last active timestamp asynchronously
199+
# to prevent blocking the request
200+
background_tasks.add_task(Users.update_user_last_active_by_id, user.id)
198201
return user
199202
else:
200203
raise HTTPException(

0 commit comments

Comments
 (0)