Skip to content

Commit

Permalink
refac: token handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed Nov 6, 2024
1 parent 60df959 commit 4616b50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion backend/open_webui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,14 @@ async def get_app_config(request: Request):
user = None
if "token" in request.cookies:
token = request.cookies.get("token")
data = decode_token(token)
try:
data = decode_token(token)
except Exception as e:
log.debug(e)
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid token",
)
if data is not None and "id" in data:
user = Users.get_user_by_id(data["id"])

Expand Down
10 changes: 9 additions & 1 deletion backend/open_webui/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ def get_current_user(
return get_current_user_by_api_key(token)

# auth by jwt token
data = decode_token(token)

try:
data = decode_token(token)
except Exception as e:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid token",
)

if data is not None and "id" in data:
user = Users.get_user_by_id(data["id"])
if user is None:
Expand Down

0 comments on commit 4616b50

Please sign in to comment.