author-id-fix
All checks were successful
deploy / deploy (push) Successful in 1m13s

This commit is contained in:
2023-11-28 12:05:39 +03:00
parent 15139249f1
commit c53b7a4c6c
7 changed files with 64 additions and 40 deletions

View File

@@ -1,5 +1,7 @@
from functools import wraps
from httpx import AsyncClient, HTTPError
from httpx import AsyncClient
from services.core import get_author
from settings import AUTH_URL
@@ -42,23 +44,13 @@ def login_required(f):
raise Exception("You are not logged in")
else:
# Добавляем author_id в контекст
context["author_id"] = user_id
author = await get_author(user_id)
if author:
context["author_id"] = author.id
elif user_id:
context["user_id"] = user_id
# Если пользователь аутентифицирован, выполняем резолвер
return await f(*args, **kwargs)
return decorated_function
def auth_request(f):
@wraps(f)
async def decorated_function(*args, **kwargs):
req = args[0]
is_authenticated, user_id = await check_auth(req)
if not is_authenticated:
raise HTTPError("please, login first")
else:
req["author_id"] = user_id
return await f(*args, **kwargs)
return decorated_function