From 198bff6e4af8ee85e2c9e517bd564958413ae7f1 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 7 May 2025 16:07:49 +0200 Subject: [PATCH] Only set the cookie if the user is not connected --- backend/src/services/ron/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/backend/src/services/ron/mod.rs b/backend/src/services/ron/mod.rs index 672464e..32995b0 100644 --- a/backend/src/services/ron/mod.rs +++ b/backend/src/services/ron/mod.rs @@ -30,14 +30,13 @@ pub async fn set_lang( let mut jar = CookieJar::from_headers(&headers); if let Some(user) = context.user { connection.set_user_lang(user.id, &ron.lang).await?; + } else { + // Only set the cookie if the user is not connected. + let cookie = Cookie::build((consts::COOKIE_LANG_NAME, ron.lang)) + .same_site(SameSite::Lax) + .path("/"); + jar = jar.add(cookie); } - - // Always set the cookie even is the user is connected in case of disconnection. - let cookie = Cookie::build((consts::COOKIE_LANG_NAME, ron.lang)) - .same_site(SameSite::Lax) - .path("/"); - jar = jar.add(cookie); - Ok((jar, StatusCode::OK)) }