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