build-fix
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from typing import Optional
|
||||
|
||||
from aiohttp.web import HTTPUnauthorized
|
||||
from aiohttp.client import ClientSession
|
||||
from pydantic import BaseModel
|
||||
from functools import wraps
|
||||
from starlette.authentication import AuthenticationBackend
|
||||
from starlette.requests import HTTPConnection
|
||||
from httpx import AsyncClient
|
||||
from httpx._exceptions import HTTPError
|
||||
from services.db import local_session
|
||||
from settings import AUTH_URL
|
||||
from orm.author import Author
|
||||
@@ -40,16 +40,14 @@ async def check_auth(req):
|
||||
else {"query": "{ session { user { id } } }"}
|
||||
)
|
||||
headers = {"Authorization": token, "Content-Type": "application/json"}
|
||||
async with ClientSession(headers=headers) as session:
|
||||
async with session.post(AUTH_URL, data=gql) as response:
|
||||
if response.status != 200:
|
||||
return False, None
|
||||
r = await response.json()
|
||||
user_id = (
|
||||
r.get("data", {}).get("session", {}).get("user", {}).get("id", None)
|
||||
)
|
||||
is_authenticated = user_id is not None
|
||||
return is_authenticated, user_id
|
||||
async with AsyncClient() as client:
|
||||
response = await client.post(AUTH_URL, headers=headers, data=gql)
|
||||
if response.status_code != 200:
|
||||
return False, None
|
||||
r = response.json()
|
||||
user_id = r.get("data", {}).get("session", {}).get("user", {}).get("id", None)
|
||||
is_authenticated = user_id is not None
|
||||
return is_authenticated, user_id
|
||||
|
||||
|
||||
async def author_id_by_user_id(user_id):
|
||||
@@ -84,7 +82,7 @@ def auth_request(f):
|
||||
req = args[0]
|
||||
is_authenticated, user_id = await check_auth(req)
|
||||
if not is_authenticated:
|
||||
raise HTTPUnauthorized()
|
||||
raise HTTPError("please, login first")
|
||||
else:
|
||||
author_id = await author_id_by_user_id(user_id)
|
||||
req["author_id"] = author_id
|
||||
|
Reference in New Issue
Block a user