less-code
All checks were successful
deploy / deploy (push) Successful in 48s

This commit is contained in:
Untone 2024-04-19 11:01:43 +03:00
parent 38c0a4e3ee
commit 63cf0b9fee

View File

@ -60,9 +60,7 @@ def login_required(f):
info = args[1]
context = info.context
req = context.get("request")
authorized = await check_auth(req)
if authorized:
user_id, user_roles = authorized
user_id, user_roles = await check_auth(req)
if user_id and isinstance(user_id, str):
context["user_id"] = user_id.strip()
author = get_author_by_user(user_id)
@ -79,16 +77,12 @@ def auth_request(f):
@wraps(f)
async def decorated_function(*args, **kwargs):
req = args[0]
authorized = await check_auth(req)
if authorized:
user_id, user_roles = authorized
user_id, user_roles = await check_auth(req)
if user_id and isinstance(user_id, str):
user_id = user_id.strip()
author = get_author_by_user(user_id)
if author and "id" in author:
req["author_id"] = author["id"]
else:
logger.error('cannot find author')
return await f(*args, **kwargs)
else:
raise HTTPException(status_code=401, detail="Unauthorized")