chore: 更新国际化翻译及 UI 组件优化
This commit is contained in:
@@ -17,6 +17,7 @@ from v1.auth.schemas import (
|
||||
PhoneSessionCreateRequest,
|
||||
SessionRefreshRequest,
|
||||
SessionResponse,
|
||||
UserByIdResponse,
|
||||
UserByPhoneResponse,
|
||||
)
|
||||
from v1.auth.service import AuthServiceGateway
|
||||
@@ -205,6 +206,41 @@ class SupabaseAuthGateway(AuthServiceGateway):
|
||||
),
|
||||
)
|
||||
|
||||
async def get_user_by_id(self, user_id: str) -> UserByIdResponse:
|
||||
try:
|
||||
admin_client = self._get_admin_client()
|
||||
user = await asyncio.to_thread(admin_client.auth.get_user_by_id, user_id)
|
||||
if user is None:
|
||||
raise _auth_error(
|
||||
status_code=404,
|
||||
code="AUTH_USER_NOT_FOUND",
|
||||
detail="User not found",
|
||||
)
|
||||
user_attrs = getattr(user, "user", user)
|
||||
return UserByIdResponse(
|
||||
id=str(getattr(user_attrs, "id", "")),
|
||||
phone=getattr(user_attrs, "phone", None),
|
||||
created_at=str(getattr(user_attrs, "created_at", "")),
|
||||
phone_confirmed_at=(
|
||||
str(getattr(user_attrs, "phone_confirmed_at", ""))
|
||||
if getattr(user_attrs, "phone_confirmed_at", None)
|
||||
else None
|
||||
),
|
||||
)
|
||||
except AuthError as exc:
|
||||
logger.warning("Get user by id failed", error_type=type(exc).__name__)
|
||||
if _is_auth_upstream_unavailable(exc):
|
||||
raise _auth_error(
|
||||
status_code=503,
|
||||
code="AUTH_SERVICE_UNAVAILABLE",
|
||||
detail=AUTH_UNAVAILABLE_DETAIL,
|
||||
) from exc
|
||||
raise _auth_error(
|
||||
status_code=404,
|
||||
code="AUTH_USER_NOT_FOUND",
|
||||
detail="User not found",
|
||||
) from exc
|
||||
|
||||
async def search_user_ids_by_phone(self, query: str, limit: int = 20) -> list[str]:
|
||||
normalized_query = _normalize_phone_search_query(query)
|
||||
if not normalized_query:
|
||||
|
||||
@@ -49,6 +49,13 @@ class UserByPhoneResponse(BaseModel):
|
||||
phone_confirmed_at: str | None = None
|
||||
|
||||
|
||||
class UserByIdResponse(BaseModel):
|
||||
id: str
|
||||
phone: str | None = None
|
||||
created_at: str
|
||||
phone_confirmed_at: str | None = None
|
||||
|
||||
|
||||
class OtpSendResponse(BaseModel):
|
||||
phone: str = Field(pattern=SUPABASE_PHONE_PATTERN)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user