This commit is contained in:
parent
40ac53d32d
commit
65a6d534c6
|
@ -30,43 +30,24 @@ async def check_auth(req) -> (bool, int | None):
|
|||
"variables": variables,
|
||||
"operationName": opeation,
|
||||
}
|
||||
# print(f"[services.auth] Graphql: {gql}")
|
||||
|
||||
try:
|
||||
# Asynchronous HTTP request to the authentication server
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(AUTH_URL, json=gql, headers=headers) as response:
|
||||
# Logging the GraphQL response
|
||||
# response_text = await response.text()
|
||||
# print(f"[services.auth] GraphQL Response: {response_text}")
|
||||
|
||||
if response.status == 200:
|
||||
# Parsing JSON response
|
||||
data = await response.json()
|
||||
errors = data.get("errors")
|
||||
if errors:
|
||||
print(f"[services.auth] errors: {errors}")
|
||||
else:
|
||||
user_id = data.get("data", {}).get(query_name, {}).get("claims", {}).get("sub")
|
||||
|
||||
if user_id:
|
||||
# Logging the retrieved user ID
|
||||
# print(f"[services.auth] User ID retrieved: {user_id}")
|
||||
return True, user_id
|
||||
else:
|
||||
# Logging when no user ID is found in the response
|
||||
# print("[services.auth] No user ID found in the response")
|
||||
pass
|
||||
else:
|
||||
# Logging when the request to the authentication server fails
|
||||
# print(f"[services.auth] Request failed with status: {response.status}")
|
||||
pass
|
||||
return bool(user_id), user_id
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
# Handling and logging exceptions during authentication check
|
||||
print(f"[services.auth] {e}")
|
||||
print(f"[services.auth] check_auth error: {e}")
|
||||
|
||||
return False, None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user