Replace process-local session cache with pluggable session cache backend

This commit is contained in:
2026-04-10 19:22:02 +02:00
parent 2157502670
commit 1dfc17f4f5
6 changed files with 100 additions and 64 deletions

View File

@@ -12,7 +12,7 @@ from __future__ import annotations
import structlog
from fastapi import APIRouter, HTTPException, Request, Response, status
from app.dependencies import DbDep, SettingsDep, invalidate_session_cache
from app.dependencies import DbDep, SessionCacheDep, SettingsDep
from app.models.auth import LoginRequest, LoginResponse, LogoutResponse
from app.services import auth_service
@@ -88,6 +88,7 @@ async def logout(
response: Response,
db: DbDep,
settings: SettingsDep,
session_cache: SessionCacheDep,
) -> LogoutResponse:
"""Invalidate the active session.
@@ -108,8 +109,8 @@ async def logout(
if token:
raw_token = await auth_service.logout(db, token, settings.session_secret)
if raw_token:
invalidate_session_cache(raw_token)
invalidate_session_cache(token)
session_cache.invalidate(raw_token)
session_cache.invalidate(token)
response.delete_cookie(key=_COOKIE_NAME)
return LogoutResponse()