This commit is contained in:
2026-01-25 16:01:48 +01:00
parent 802c1b40d3
commit 71f8d4cd51

View File

@@ -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)):