Spaces:
Runtime error
Runtime error
Download app/middleware/admin_auth.py from BuildersAI/buildersai: direct link, hf CLI and curl.
- Browser
- Download file 709 Bytes
-
https://huggingface.co/spaces/BuildersAI/buildersai/resolve/main/app/middleware/admin_auth.py
- Command line
-
hf download hf://spaces/BuildersAI/buildersai/app/middleware/admin_auth.py
-
curl -L -o admin_auth.py https://huggingface.co/spaces/BuildersAI/buildersai/resolve/main/app/middleware/admin_auth.py
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 | |