I'm so far unable to unset a session through a logout
endpoint I have created in Rocket.
Below is the code that creates the cookie:
impl AuthToken {
pub fn from_string(string: String) -> Self {
AuthToken(string)
}
pub fn to_string_ptr(&self) -> &String {
&self.0
}
pub fn as_cookie(&self) -> Cookie<'static> {
let clone = self.to_string();
Cookie::build("session-token", clone)
.path("/")
.same_site(SameSite::Strict)
.http_only(true)
.finish()
}
}
And this is the code that attempts to destroy it
#[post("/logout")]
pub fn logout(mut cookies: Cookies) -> APIResponse {
cookies.remove(Cookie::named("session-token"));
ok().data(json!({
"success": true
}))
}
The cookie is added wither when POST '/signup' or POST '/login' is called successfully.
In Chrome devtools you can see the cookie being set in the POST '/login' response.
Then I logout using POST '/logout', and get this response:
At this point I do a hard refresh. Afterwards GET '/get-profile' is called which shouldn't work when logged out, but it still sends the cookie in the request headers.
So it seems the session cookie isn't being properly unset, is there a proper way to do this in Rocket?