From 1677498a8e3ae2471f4d8aafee6ab72ce3948b22 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 23 Jul 2026 12:04:35 +0000 Subject: [PATCH] feat: add admin-only RBAC demo endpoint with require_roles --- app/routers/auth.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/routers/auth.py b/app/routers/auth.py index 2903292..27af060 100644 --- a/app/routers/auth.py +++ b/app/routers/auth.py @@ -8,7 +8,7 @@ from fastapi import APIRouter, Depends from sqlalchemy.ext.asyncio import AsyncSession from app.core.database import get_db -from app.core.security import get_current_user +from app.core.security import get_current_user, require_roles from app.models.user import User from app.schemas.auth import ( LoginRequest, @@ -51,3 +51,11 @@ async def refresh( @router.get("/me", response_model=UserOut) async def me(current_user: Annotated[User, Depends(get_current_user)]) -> User: return current_user + + +@router.get("/admin-only", response_model=UserOut) +async def admin_only( + current_user: Annotated[User, Depends(require_roles("Admin/Jerome", "Admin/Wahab"))], +) -> User: + """Example RBAC-protected endpoint — only Admins can access.""" + return current_user