py-builder-too

This commit is contained in:
2024-02-17 11:52:26 +03:00
parent 70079c38ad
commit 899cb05c1b
4 changed files with 88 additions and 21 deletions

View File

@@ -39,15 +39,22 @@ async def check_auth(req) -> str | None:
}
# Asynchronous HTTP request to the authentication server
async with ClientSession() as session:
async with session.post(AUTH_URL, json=gql, headers=headers) as response:
async with session.post(
AUTH_URL, json=gql, headers=headers
) as response:
if response.status == 200:
data = await response.json()
errors = data.get('errors')
if errors:
logger.error(f'{errors}')
else:
user_id = data.get('data', {}).get(query_name, {}).get('claims', {}).get('sub')
logger.info(f'[services.auth] got user_id: {user_id}')
user_id = (
data.get('data', {})
.get(query_name, {})
.get('claims', {})
.get('sub')
)
logger.info(f'got user_id: {user_id}')
return user_id
except Exception as e:
# Handling and logging exceptions during authentication check