from fastapi import Depends, HTTPException, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from jose import JWTError, jwt from app.config import settings bearer = HTTPBearer(auto_error=False) async def get_current_user( creds: HTTPAuthorizationCredentials | None = Depends(bearer), ) -> dict: if creds is None: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) try: return jwt.decode(creds.credentials, settings.SECRET_KEY, algorithms=["HS256"]) except JWTError: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) async def get_tenant_id(user: dict = Depends(get_current_user)) -> str: return user["tenant_id"]