Only set the cookie if the user is not connected
This commit is contained in:
parent
deb6b8649e
commit
198bff6e4a
1 changed files with 6 additions and 7 deletions
|
|
@ -30,14 +30,13 @@ pub async fn set_lang(
|
||||||
let mut jar = CookieJar::from_headers(&headers);
|
let mut jar = CookieJar::from_headers(&headers);
|
||||||
if let Some(user) = context.user {
|
if let Some(user) = context.user {
|
||||||
connection.set_user_lang(user.id, &ron.lang).await?;
|
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))
|
Ok((jar, StatusCode::OK))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue