server-start-8

This commit is contained in:
Tony Rewin 2023-10-03 19:19:04 +03:00
parent 465404bf10
commit 46cc285c2d
2 changed files with 10 additions and 12 deletions

View File

@ -6,7 +6,7 @@ sqlalchemy
graphql-core
gql
uvicorn
aiohttp
httpx
######## development deps
isort
brunette

View File

@ -4,7 +4,7 @@ from functools import wraps
from starlette.authentication import AuthenticationBackend
from starlette.requests import HTTPConnection
from graphql.error import GraphQLError
from aiohttp import ClientSession as AsyncClient
from httpx import AsyncClient
from services.db import local_session
from settings import AUTH_URL
from orm.author import Author
@ -45,16 +45,14 @@ async def check_auth(req):
else {"query": "{ session { user { id } } }"}
)
headers = {"Authorization": token, "Content-Type": "application/json"}
async with AsyncClient(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
def author_id_by_user_id(user_id):