from fastapi import Depends
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from app.core.config import settings
from shared.security import CurrentUser
from shared.exceptions import UnauthorizedError
bearer = HTTPBearer(auto_error=False)
async def get_current_user(credentials: HTTPAuthorizationCredentials | None = Depends(bearer)):
    if not settings.auth_required:
        return CurrentUser(user_id="test-user", username="test", roles=["tenant_admin"])
    if not credentials: raise UnauthorizedError("Authentication required")
    return CurrentUser(user_id="token-user", username="token", roles=[])
