Fix monitoring TG auth status
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 30s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 30s
This commit is contained in:
@@ -23,6 +23,7 @@ router = APIRouter()
|
|||||||
class AuthStatus(BaseModel):
|
class AuthStatus(BaseModel):
|
||||||
authorized: bool
|
authorized: bool
|
||||||
username: str | None = None
|
username: str | None = None
|
||||||
|
display_name: str | None = None
|
||||||
phone: str | None = None
|
phone: str | None = None
|
||||||
|
|
||||||
|
|
||||||
@@ -73,10 +74,13 @@ async def _require_channel_scope(
|
|||||||
|
|
||||||
@router.get("/auth/status", response_model=AuthStatus, dependencies=[Depends(require_admin)])
|
@router.get("/auth/status", response_model=AuthStatus, dependencies=[Depends(require_admin)])
|
||||||
async def auth_status() -> AuthStatus:
|
async def auth_status() -> AuthStatus:
|
||||||
username = await tg.current_username()
|
authorized = await tg.is_authorized()
|
||||||
|
username = await tg.current_username() if authorized else None
|
||||||
|
display_name = await tg.current_display_name() if authorized else None
|
||||||
return AuthStatus(
|
return AuthStatus(
|
||||||
authorized=username is not None,
|
authorized=authorized,
|
||||||
username=username,
|
username=username,
|
||||||
|
display_name=display_name,
|
||||||
phone=settings.tg_phone,
|
phone=settings.tg_phone,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,19 @@ async def current_username() -> str | None:
|
|||||||
me = await client.get_me()
|
me = await client.get_me()
|
||||||
if me is None:
|
if me is None:
|
||||||
return None
|
return None
|
||||||
return me.username or str(me.id)
|
return me.username
|
||||||
|
|
||||||
|
|
||||||
|
async def current_display_name() -> str | None:
|
||||||
|
client = await start_client()
|
||||||
|
if not await client.is_user_authorized():
|
||||||
|
return None
|
||||||
|
me = await client.get_me()
|
||||||
|
if me is None:
|
||||||
|
return None
|
||||||
|
parts = [getattr(me, "first_name", None), getattr(me, "last_name", None)]
|
||||||
|
name = " ".join(part for part in parts if part).strip()
|
||||||
|
return name or me.username or None
|
||||||
|
|
||||||
|
|
||||||
_pending_phone_code_hash: str | None = None
|
_pending_phone_code_hash: str | None = None
|
||||||
|
|||||||
Reference in New Issue
Block a user