This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user