mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 21:42:58 +00:00
refac: token handling
This commit is contained in:
parent
60df959875
commit
4616b508b1
@ -2224,7 +2224,14 @@ async def get_app_config(request: Request):
|
|||||||
user = None
|
user = None
|
||||||
if "token" in request.cookies:
|
if "token" in request.cookies:
|
||||||
token = request.cookies.get("token")
|
token = request.cookies.get("token")
|
||||||
|
try:
|
||||||
data = decode_token(token)
|
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:
|
if data is not None and "id" in data:
|
||||||
user = Users.get_user_by_id(data["id"])
|
user = Users.get_user_by_id(data["id"])
|
||||||
|
|
||||||
|
@ -91,7 +91,15 @@ def get_current_user(
|
|||||||
return get_current_user_by_api_key(token)
|
return get_current_user_by_api_key(token)
|
||||||
|
|
||||||
# auth by jwt token
|
# auth by jwt token
|
||||||
|
|
||||||
|
try:
|
||||||
data = decode_token(token)
|
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:
|
if data is not None and "id" in data:
|
||||||
user = Users.get_user_by_id(data["id"])
|
user = Users.get_user_by_id(data["id"])
|
||||||
if user is None:
|
if user is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user