Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Mar 21, 2024
1 parent 907d640 commit f5c169e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f5c169e

Please sign in to comment.