diff --git a/backend/server/main.py b/backend/server/main.py index 5fbf403..f6eb952 100644 --- a/backend/server/main.py +++ b/backend/server/main.py @@ -32,9 +32,12 @@ ], ) + class EnsureUserIDMiddleware(BaseHTTPMiddleware): - async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: - user_id = request.cookies.get('user_id') + async def dispatch( + self, request: Request, call_next: RequestResponseEndpoint + ) -> Response: + user_id = request.cookies.get("user_id") if not user_id: user_id = str(uuid.uuid4()) # Generate a new user_id request.state.user_id = user_id # Set user_id in request state @@ -45,6 +48,7 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) - response = await call_next(request) return response + app.add_middleware(EnsureUserIDMiddleware) ROOT = Path(__file__).parent.parent