From 60a89146da827674f7e3558183e573bed4726e9f Mon Sep 17 00:00:00 2001 From: Game_Time <108236317+RayBytes@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:16:23 +0500 Subject: [PATCH] Update core.py --- api/core.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/core.py b/api/core.py index fe16cd9..073608c 100644 --- a/api/core.py +++ b/api/core.py @@ -12,7 +12,14 @@ from dotenv import load_dotenv load_dotenv() router = fastapi.APIRouter(tags=['core']) + async def check_core_auth(request): + """ + + ### Checks the request's auth + Auth is taken from environment variable `CORE_API_KEY` + + """ received_auth = request.headers.get('Authorization') if received_auth != os.getenv('CORE_API_KEY'): @@ -20,14 +27,12 @@ async def check_core_auth(request): @router.get('/users') async def get_users(discord_id: int, incoming_request: fastapi.Request): - auth_error = await check_core_auth(incoming_request) - - if auth_error: + auth = await check_core_auth(incoming_request) + if auth: return auth_error - user = await users.by_discord_id(discord_id) - - if not user: + # Get user by discord ID + if not await users.by_discord_id(discord_id): return fastapi.Response(status_code=404, content='User not found.') return user