File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -259,15 +259,17 @@ async def read_dashboard(
259
259
@app .get ("/profile" )
260
260
async def read_profile (
261
261
params : dict = Depends (common_authenticated_parameters ),
262
- email_update_requested : Optional [str ] = "false"
262
+ email_update_requested : Optional [str ] = "false" ,
263
+ email_updated : Optional [str ] = "false"
263
264
):
264
265
# Add image constraints to the template context
265
266
params .update ({
266
267
"max_file_size_mb" : MAX_FILE_SIZE / (1024 * 1024 ), # Convert bytes to MB
267
268
"min_dimension" : MIN_DIMENSION ,
268
269
"max_dimension" : MAX_DIMENSION ,
269
270
"allowed_formats" : list (ALLOWED_CONTENT_TYPES .keys ()),
270
- "email_update_requested" : email_update_requested
271
+ "email_update_requested" : email_update_requested ,
272
+ "email_updated" : email_updated
271
273
})
272
274
return templates .TemplateResponse (params ["request" ], "users/profile.html" , params )
273
275
Original file line number Diff line number Diff line change @@ -195,9 +195,20 @@ async def register(
195
195
refresh_token = create_refresh_token (data = {"sub" : db_user .email })
196
196
# Set cookie
197
197
response = RedirectResponse (url = "/" , status_code = 303 )
198
- response .set_cookie (key = "access_token" , value = access_token , httponly = True )
199
- response .set_cookie (key = "refresh_token" ,
200
- value = refresh_token , httponly = True )
198
+ response .set_cookie (
199
+ key = "access_token" ,
200
+ value = access_token ,
201
+ httponly = True ,
202
+ secure = True ,
203
+ samesite = "strict"
204
+ )
205
+ response .set_cookie (
206
+ key = "refresh_token" ,
207
+ value = refresh_token ,
208
+ httponly = True ,
209
+ secure = True ,
210
+ samesite = "strict"
211
+ )
201
212
202
213
return response
203
214
@@ -390,25 +401,28 @@ async def confirm_email_update(
390
401
session .commit ()
391
402
392
403
# Create new tokens with the updated email
393
- access_token = create_access_token (data = {"sub" : new_email })
404
+ access_token = create_access_token (data = {"sub" : new_email , "fresh" : True })
394
405
refresh_token = create_refresh_token (data = {"sub" : new_email })
395
406
407
+ # Set cookies before redirecting
396
408
response = RedirectResponse (
397
409
url = "/profile?email_updated=true" ,
398
410
status_code = 303
399
411
)
412
+
413
+ # Add secure cookie attributes
400
414
response .set_cookie (
401
415
key = "access_token" ,
402
416
value = access_token ,
403
417
httponly = True ,
404
418
secure = True ,
405
- samesite = "strict "
419
+ samesite = "lax "
406
420
)
407
421
response .set_cookie (
408
422
key = "refresh_token" ,
409
423
value = refresh_token ,
410
424
httponly = True ,
411
425
secure = True ,
412
- samesite = "strict "
426
+ samesite = "lax "
413
427
)
414
428
return response
You can’t perform that action at this time.
0 commit comments