fix(redis): 修复 Redis 流读取兼容性问题

- 支持 bytes 和 str 类型的 entry_id
- 支持 list 类型响应格式
- 优化 payload 解码处理
This commit is contained in:
qzl
2026-03-11 21:33:25 +08:00
parent e4f69a64bd
commit 18db6c50e7
17 changed files with 359 additions and 54 deletions
+42 -2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
from typing import Annotated
from uuid import UUID
@@ -14,6 +15,7 @@ from core.auth.models import CurrentUser
from core.config.settings import config
from core.db import get_db
from core.logging import get_logger
from services.base.supabase import supabase_service
from v1.auth.gateway import SupabaseAuthGateway
from v1.users.repository import SQLAlchemyUserRepository
from v1.users.service import AuthLookupAdapter, UserService
@@ -51,7 +53,41 @@ def get_jwt_verifier() -> JwtVerifier:
return _jwt_verifier
def get_current_user(authorization: str | None = Header(default=None)) -> CurrentUser:
async def _verify_user_with_supabase(token: str) -> CurrentUser | None:
try:
client = supabase_service.get_client()
except Exception as exc: # noqa: BLE001
logger.warning("Supabase fallback unavailable", reason=str(exc))
return None
try:
response = await asyncio.to_thread(client.auth.get_user, token)
except Exception as exc: # noqa: BLE001
logger.warning("Supabase token fallback validation failed", reason=str(exc))
return None
user = getattr(response, "user", None)
if user is None:
return None
user_id = getattr(user, "id", None)
if not isinstance(user_id, str) or not user_id:
return None
try:
parsed_id = UUID(user_id)
except ValueError:
return None
email = getattr(user, "email", None)
role = getattr(user, "role", None)
return CurrentUser(
id=parsed_id,
email=email if isinstance(email, str) else None,
role=role if isinstance(role, str) else None,
)
async def get_current_user(
authorization: str | None = Header(default=None),
) -> CurrentUser:
if not authorization:
logger.warning("JWT validation failed: missing authorization header")
raise HTTPException(status_code=401, detail="Unauthorized")
@@ -71,7 +107,11 @@ def get_current_user(authorization: str | None = Header(default=None)) -> Curren
error_type=type(exc).__name__,
reason=str(exc),
)
raise HTTPException(status_code=401, detail="Unauthorized") from exc
fallback_user = await _verify_user_with_supabase(token)
if fallback_user is None:
raise HTTPException(status_code=401, detail="Unauthorized") from exc
logger.info("JWT fallback validation succeeded", user_id=str(fallback_user.id))
return fallback_user
subject = payload.get("sub")
if not isinstance(subject, str) or not subject: