From 71f8d4cd51a6d417544a6a182e0e9a96ff965588 Mon Sep 17 00:00:00 2001 From: mahmamdouh Date: Sun, 25 Jan 2026 16:01:48 +0100 Subject: [PATCH] fix --- backend/auth_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/auth_utils.py b/backend/auth_utils.py index 5a497e9..83473ed 100644 --- a/backend/auth_utils.py +++ b/backend/auth_utils.py @@ -38,16 +38,24 @@ async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = De headers={"WWW-Authenticate": "Bearer"}, ) try: + print(f"DEBUG AUTH: Decoding token: {token[:10]}...") payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) username: str = payload.get("sub") + print(f"DEBUG AUTH: Username from token: {username}") if username is None: + print("DEBUG AUTH: Username is None") raise credentials_exception token_data = schemas.TokenData(username=username) - except JWTError: + except JWTError as e: + print(f"DEBUG AUTH: JWTError: {e}") raise credentials_exception + user = db.query(models.User).filter(models.User.username == token_data.username).first() if user is None: + print(f"DEBUG AUTH: User {token_data.username} not found in DB") raise credentials_exception + + print(f"DEBUG AUTH: User found: {user.username}, Is Admin: {user.is_admin}") return user async def get_current_admin_user(current_user: models.User = Depends(get_current_user)):