Replies: 1 comment 1 reply
-
use actix_web_lab::middleware::{from_fn, Next};
App::new()
// ...
.wrap(from_fn(refresh_cookies)) use actix_web::{
body::MessageBody,
cookie::Cookie,
dev::{ServiceRequest, ServiceResponse},
Error,
};
use actix_web_lab::middleware::{from_fn, Next};
async fn refresh_cookies(
req: ServiceRequest,
next: Next<impl MessageBody>,
) -> Result<ServiceResponse<impl MessageBody>, Error> {
let auth_cookie = req.cookie("web-auth").clone();
let mut res = next.call(req).await?;
if let Some(cookie) = auth_cookie {
let refreshed_cookie = Cookie::build(cookie.name(), cookie.value())
.domain("example.com")
// re-apply other original settings
.finish();
res.response_mut().add_cookie(&refreshed_cookie);
};
Ok(res)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Necoo33
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I currently coded a jwt authentication flow with assigning it's value to cookie and i want to add a cookie refresher middleware to that. In every page load it should resend the authentication cookie if it's already exist.
So how can i mutate my cookies in a middleware?
Beta Was this translation helpful? Give feedback.
All reactions