Skip to content

Commit f5e9352

Browse files
committed
fix: Set access token in cookies when refreshing tokens
1 parent f36918f commit f5e9352

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/controllers/auth_controller.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ async def login(request: Request, login_request: Annotated[LoginRequest, Body()]
105105
response = JSONResponse(
106106
status_code=status.HTTP_200_OK,
107107
content=json_encoder({
108-
"access_token": access_token,
109108
"user_id": user_id,
110109
"code": "success",
111110
"message": "Login successful"
@@ -316,14 +315,22 @@ async def refresh_token_endpoint(request: Request) -> JSONResponse:
316315
try:
317316
payload = await verify_refresh_token(refresh_token)
318317
new_access_token = await create_access_token(payload["user_id"])
319-
return JSONResponse(
318+
response = JSONResponse(
320319
status_code=status.HTTP_200_OK,
321320
content=json_encoder({
322-
"access_token": new_access_token,
323321
"code": "success",
324322
"message": "Access token refreshed"
325323
}),
326324
)
325+
response.set_cookie(
326+
key="access_token",
327+
value=new_access_token,
328+
httponly=True,
329+
secure=settings.SECURE,
330+
samesite="none" if settings.SECURE else "lax",
331+
max_age=60 * 15
332+
)
333+
return response
327334
except ExpiredSignatureError:
328335
return JSONResponse(
329336
status_code=status.HTTP_401_UNAUTHORIZED,

0 commit comments

Comments
 (0)