From 0f3aa43b89ccb8d899fa8aaaa557c81184aa78c5 Mon Sep 17 00:00:00 2001 From: dvirlabs <114520947+dvirlabs@users.noreply.github.com> Date: Mon, 8 Dec 2025 15:04:37 +0200 Subject: [PATCH] Update backend to setup admin --- backend/auth_utils.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/auth_utils.py b/backend/auth_utils.py index 0168ac9..f6925fc 100644 --- a/backend/auth_utils.py +++ b/backend/auth_utils.py @@ -58,6 +58,8 @@ def decode_token(token: str) -> dict: def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security)) -> dict: """Get current user from JWT token (for protected routes)""" + from user_db_utils import get_user_by_id + token = credentials.credentials payload = decode_token(token) user_id = payload.get("sub") @@ -66,7 +68,21 @@ def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(securit status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid authentication credentials", ) - return {"user_id": int(user_id), "username": payload.get("username")} + + # Get full user info from database to include is_admin + user = get_user_by_id(int(user_id)) + if not user: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="User not found", + ) + + return { + "user_id": user["id"], + "username": user["username"], + "display_name": user["display_name"], + "is_admin": user.get("is_admin", False) + } # Optional dependency - returns None if no token provided