server-start-7

This commit is contained in:
Tony Rewin 2023-10-03 19:16:37 +03:00
parent e6d1fa5b07
commit 465404bf10
3 changed files with 18 additions and 15 deletions

View File

@ -1,4 +0,0 @@
isort
brunette
flake8
mypy

View File

@ -2,9 +2,14 @@ sentry-sdk
aioredis aioredis
ariadne ariadne
starlette starlette
starlette
sqlalchemy sqlalchemy
graphql-core graphql-core
gql gql
uvicorn uvicorn
httpx aiohttp
######## development deps
isort
brunette
flake8
mypy
its

View File

@ -4,7 +4,7 @@ from functools import wraps
from starlette.authentication import AuthenticationBackend from starlette.authentication import AuthenticationBackend
from starlette.requests import HTTPConnection from starlette.requests import HTTPConnection
from graphql.error import GraphQLError from graphql.error import GraphQLError
from httpx import AsyncClient from aiohttp import ClientSession as AsyncClient
from services.db import local_session from services.db import local_session
from settings import AUTH_URL from settings import AUTH_URL
from orm.author import Author from orm.author import Author
@ -45,12 +45,14 @@ async def check_auth(req):
else {"query": "{ session { user { id } } }"} else {"query": "{ session { user { id } } }"}
) )
headers = {"Authorization": token, "Content-Type": "application/json"} headers = {"Authorization": token, "Content-Type": "application/json"}
async with AsyncClient() as client: async with AsyncClient(headers=headers) as session:
response = await client.post(AUTH_URL, headers=headers, data=gql) async with session.post(AUTH_URL, data=gql) as response:
if response.status_code != 200: if response.status != 200:
return False, None return False, None
r = response.json() r = await response.json()
user_id = r.get("data", {}).get("session", {}).get("user", {}).get("id", None) user_id = (
r.get("data", {}).get("session", {}).get("user", {}).get("id", None)
)
is_authenticated = user_id is not None is_authenticated = user_id is not None
return is_authenticated, user_id return is_authenticated, user_id