XThomasBU commited on
Commit
06e6599
·
1 Parent(s): 2406d86

potential bug fix

Browse files
Files changed (1) hide show
  1. code/app.py +7 -3
code/app.py CHANGED
@@ -94,10 +94,15 @@ async def get_user_info_from_cookie(request: Request):
94
 
95
 
96
  async def del_user_info_from_cookie(request: Request, response: Response):
 
97
  response.delete_cookie("X-User-Info")
98
  response.delete_cookie("session_token")
 
 
99
  session_token = request.cookies.get("session_token")
100
- if session_token:
 
 
101
  del session_store[session_token]
102
 
103
 
@@ -191,8 +196,7 @@ async def auth_google(request: Request):
191
  response = RedirectResponse(url="/post-signin", status_code=303)
192
  response.set_cookie(key="session_token", value=session_token)
193
  response.set_cookie(
194
- key="X-User-Info", value=user_info_encoded
195
- ) # TODO: is the flag httponly=True necessary?
196
  return response
197
  except Exception as e:
198
  print(f"Error during Google OAuth callback: {e}")
 
94
 
95
 
96
  async def del_user_info_from_cookie(request: Request, response: Response):
97
+ # Delete cookies from the response
98
  response.delete_cookie("X-User-Info")
99
  response.delete_cookie("session_token")
100
+
101
+ # Get the session token from the request cookies
102
  session_token = request.cookies.get("session_token")
103
+
104
+ # Check if the session token exists in the session_store before deleting
105
+ if session_token and session_token in session_store:
106
  del session_store[session_token]
107
 
108
 
 
196
  response = RedirectResponse(url="/post-signin", status_code=303)
197
  response.set_cookie(key="session_token", value=session_token)
198
  response.set_cookie(
199
+ key="X-User-Info", value=user_info_encoded, httponly=True) # TODO: is the flag httponly=True necessary?
 
200
  return response
201
  except Exception as e:
202
  print(f"Error during Google OAuth callback: {e}")