aboutsummaryrefslogtreecommitdiffstats
path: root/backend/authentication
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-03-15 02:10:37 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-03-15 02:16:28 +0300
commit7c46099b98bc23e373d78c3ff9739a6a26deb78a (patch)
tree630e5838814eba27f4e7b51ea5fbcfbdad17beee /backend/authentication
parentAdds Logging Support (diff)
Adds Logging To Helpers
Adds logging to the CORS setup, user, and discord helpers. Log statements have been setup in a way to maximize information for local development and prod debugging, while minimizing average load on the prod version. Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/authentication')
-rw-r--r--backend/authentication/user.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/backend/authentication/user.py b/backend/authentication/user.py
index 857c2ed..18fa935 100644
--- a/backend/authentication/user.py
+++ b/backend/authentication/user.py
@@ -1,3 +1,4 @@
+import logging
import typing as t
import jwt
@@ -7,6 +8,8 @@ from starlette.requests import Request
from backend.constants import SECRET_KEY
from backend.discord import fetch_user_details
+logger = logging.getLogger(__name__)
+
class User(BaseUser):
"""Starlette BaseUser implementation for JWT authentication."""
@@ -35,6 +38,7 @@ class User(BaseUser):
return jwt.decode(self.token, SECRET_KEY, algorithms=["HS256"])
async def fetch_admin_status(self, request: Request) -> bool:
+ logger.debug(f"Checking admin status for user with ID: {self.payload['id']}")
self.admin = await request.state.db.admins.find_one(
{"_id": self.payload["id"]}
) is not None
@@ -43,6 +47,7 @@ class User(BaseUser):
async def refresh_data(self) -> None:
"""Fetches user data from discord, and updates the instance."""
+ logger.debug(f"Updating user info for user with ID: {self.payload['id']}")
self.payload = await fetch_user_details(self.decoded_token.get("token"))
updated_info = self.decoded_token