summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api/deps.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/deps.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/deps.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/deps.py b/packages/meshbay-hub/src/meshbay_hub/api/deps.py
index cb637f3..7a580ad 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/deps.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/deps.py
@@ -2,8 +2,6 @@
FastAPI shared dependencies — injected via Depends().
"""
-from collections.abc import AsyncGenerator
-
from fastapi import Depends, Header, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
@@ -12,6 +10,13 @@ from meshbay_hub.auth import decode_access_token
from meshbay_hub.db.engine import get_db
from meshbay_hub.db.models import User
+_admin_usernames: set[str] = set()
+
+
+def set_admin_usernames(usernames: list[str]) -> None:
+ global _admin_usernames
+ _admin_usernames = set(usernames)
+
async def get_current_user(
authorization: str = Header(...),
@@ -45,3 +50,12 @@ async def get_current_user(
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
detail=f"Account {user.status}")
return user
+
+
+async def require_admin(
+ current_user: User = Depends(get_current_user),
+) -> User:
+ if current_user.username not in _admin_usernames:
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
+ detail="Admin access required")
+ return current_user