This commit is contained in:
@@ -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")
|
||||
|
Reference in New Issue
Block a user