Files
malenia-backend/core/deps.py
hexdev 97a4e819d6 feat(sub): handling upgrade/downgrade
rw integration and /me endpoints are left
2026-08-02 14:16:57 +07:00

30 lines
946 B
Python

from fastapi import Depends, HTTPException, Request
from sqlalchemy.ext.asyncio import AsyncSession
from config import cfg
from core.auth import jwt
from db.session import get_db
from external.pally import PallyClient
from schemas.dto import AuthContext
from services.subscriptions import sync_user_subscription
async def get_auth_context(
request: Request, session: AsyncSession = Depends(get_db)
) -> AuthContext | None:
auth = request.headers.get("Authorization")
if not auth:
raise HTTPException(status_code=403, detail="No authorization provided.")
if auth.startswith("Bearer"):
token = auth.removeprefix("Bearer ").strip()
ctx = await jwt.authorize(token, session)
await sync_user_subscription(session, user=ctx.user)
await session.commit()
return ctx
def get_pally_client() -> PallyClient:
return PallyClient(api_token=cfg.pally_token, payer_pays_commission=True)