logs-fixes-debug
Some checks failed
deploy / deploy (push) Failing after 5s

This commit is contained in:
2024-01-23 23:13:49 +03:00
parent 80fed4049a
commit 9b03e625f4
7 changed files with 141 additions and 120 deletions

View File

@@ -5,6 +5,10 @@ from starlette.exceptions import HTTPException
from services.core import get_author_by_user
from settings import AUTH_URL
import logging
logger = logging.getLogger("[services.auth] ")
logger.setLevel(logging.DEBUG)
async def check_auth(req) -> str | None:
token = req.headers.get("Authorization")
@@ -38,14 +42,14 @@ async def check_auth(req) -> str | None:
data = await response.json()
errors = data.get("errors")
if errors:
print(f"[services.auth] errors: {errors}")
logger.error(f"{errors}")
else:
user_id = data.get("data", {}).get(query_name, {}).get("claims", {}).get("sub")
print(f"[services.auth] got user_id: {user_id}")
logger.info(f"[services.auth] got user_id: {user_id}")
return user_id
except Exception as e:
# Handling and logging exceptions during authentication check
print(f"[services.auth] {e}")
logger.error(e)
if not user_id:
raise HTTPException(status_code=401, detail="Unauthorized")