inbox-debug-7

This commit is contained in:
Untone 2024-01-24 15:26:16 +03:00
parent cccaf16817
commit 751d91562e
2 changed files with 29 additions and 23 deletions

View File

@ -28,6 +28,7 @@ async def load_messages(
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
): ):
"""load :limit messages for :chat_id with :offset""" """load :limit messages for :chat_id with :offset"""
logger.info("load_messages")
messages = [] messages = []
try: try:
message_ids = [] + (ids or []) message_ids = [] + (ids or [])
@ -63,6 +64,7 @@ async def load_messages(
@login_required @login_required
async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]: async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]:
"""load :limit chats of current user with :offset""" """load :limit chats of current user with :offset"""
logger.info("load_chats")
author_id = info.context["author_id"] author_id = info.context["author_id"]
chats = [] chats = []
try: try:

View File

@ -12,8 +12,10 @@ logger.setLevel(logging.DEBUG)
async def check_auth(req) -> str | None: async def check_auth(req) -> str | None:
token = req.headers.get("Authorization") logger.debug("checking auth...")
user_id = "" user_id = ""
try:
token = req.headers.get("Authorization")
if token: if token:
# Logging the authentication token # Logging the authentication token
query_name = "validate_jwt_token" query_name = "validate_jwt_token"
@ -34,7 +36,6 @@ async def check_auth(req) -> str | None:
"variables": variables, "variables": variables,
"operationName": operation, "operationName": operation,
} }
try:
# Asynchronous HTTP request to the authentication server # Asynchronous HTTP request to the authentication server
async with ClientSession() as session: 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:
@ -67,6 +68,9 @@ def login_required(f):
author = get_author_by_user(user_id) author = get_author_by_user(user_id)
if author and "id" in author: if author and "id" in author:
context["author_id"] = author["id"] context["author_id"] = author["id"]
else:
logger.debug(author)
HTTPException(status_code=401, detail="Unauthorized")
return await f(*args, **kwargs) return await f(*args, **kwargs)
return decorated_function return decorated_function