forked from mtusi2026/mtusi2026lab2
Исправления после проверки: кэш, cursor, обработка ошибок
This commit is contained in:
+17
-3
@@ -52,14 +52,28 @@ async def get_current_user(
|
||||
token = parse_bearer(authorization)
|
||||
session_store = request.app.state.session_store
|
||||
storage = request.app.state.storage
|
||||
session = await session_store.get(token)
|
||||
|
||||
try:
|
||||
session = await session_store.get(token)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=503, detail="unavailable")
|
||||
|
||||
if session is None:
|
||||
raise HTTPException(status_code=401, detail="unauthorized")
|
||||
|
||||
expires_at = datetime.fromisoformat(session["expires_at"].replace("Z", "+00:00"))
|
||||
if expires_at <= datetime.now(timezone.utc):
|
||||
await session_store.delete(token)
|
||||
try:
|
||||
await session_store.delete(token)
|
||||
except Exception:
|
||||
pass
|
||||
raise HTTPException(status_code=401, detail="unauthorized")
|
||||
user = await storage.get_user(session["user_id"])
|
||||
|
||||
try:
|
||||
user = await storage.get_user(session["user_id"])
|
||||
except Exception:
|
||||
raise HTTPException(status_code=503, detail="unavailable")
|
||||
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="unauthorized")
|
||||
return user, token
|
||||
|
||||
Reference in New Issue
Block a user