Files
malenia-backend/core/auth/fetch_sub.py

18 lines
504 B
Python

from sqlalchemy.ext.asyncio import AsyncSession
from db.models import User
from repositories.users import UserRepository
from schemas.jwt import ServiceJWTPayload
async def fetch_subject_from_service(
payload: ServiceJWTPayload, session: AsyncSession
) -> User | None:
repo = UserRepository(session)
if payload.acting_as.startswith("telegram:"):
telegram_id = int(payload.acting_as.split("telegram:")[1])
return await repo.get_user_by_telegram_id(telegram_id)
return