buildersai / app /middleware /admin_auth.py
Kushal
Initial deployment: FastAPI backend with Docker
f3997d4
Raw
History Blame Contribute Delete
709 Bytes
"""
Admin authentication middleware.
"""
from fastapi import Depends, HTTPException, status
from app.middleware.auth import get_current_user
from app.database.models import User
def get_current_admin_user(current_user: User = Depends(get_current_user)) -> User:
"""
Verify that the current user is an admin.
Args:
current_user: Current authenticated user
Returns:
User object if admin
Raises:
HTTPException: If user is not an admin
"""
if not current_user.is_admin:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Admin privileges required"
)
return current_user