Spaces:
Paused

yaz / src /apps /auth /api /dependencies.py
anaselamr's picture
feat: Sprint 44 — ProductRegistry, Azul/Luiz layer, 13 migrations, doc cleanup
383d839
Raw History Blame Contribute Delete
1.4 kB
"""
Authentication Dependencies
Common dependencies for FastAPI endpoints requiring authentication.
All functions delegate to the canonical core.dependencies module.
"""
from typing import Optional
from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from core.dependencies import get_current_user, CurrentUser
# AuthUser alias for backward compatibility — CurrentUser has all required attrs:
# .id, .user_id, .email, .username, .full_name, .role, .is_admin, .is_active,
# .is_verified, .tenant_id, .permissions, .last_login
AuthUser = CurrentUser
security = HTTPBearer()
async def get_current_active_user(
current_user: CurrentUser = Depends(get_current_user),
) -> CurrentUser:
"""Dependency to ensure the current user is active (always True post-auth)."""
if not current_user.is_active:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Inactive user",
)
return current_user
async def get_current_admin_user(
current_user: CurrentUser = Depends(get_current_user),
) -> CurrentUser:
"""Dependency to ensure the current user is an admin."""
if not current_user.is_admin:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Admin access required",
)
return current_user