from fastapi import APIRouter, Depends, HTTPException, status from app.api.deps import get_auth_service from app.schemas.auth import LoginRequest, RefreshRequest, TokenResponse from app.services.auth import AuthService router = APIRouter(prefix="/auth", tags=["Auth"]) @router.post("/login", response_model=TokenResponse) async def login( body: LoginRequest, auth_svc: AuthService = Depends(get_auth_service), ): result = await auth_svc.authenticate(body.telegram_id, body.secret_key) if result is None: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials", ) return result @router.post("/refresh", response_model=TokenResponse) async def refresh( body: RefreshRequest, auth_svc: AuthService = Depends(get_auth_service), ): try: return auth_svc.refresh_access_token(body.refresh_token) except ValueError as e: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=str(e), )