create_cookie.rs 647 B

12345678910111213141516171819202122
  1. use actix_web::cookie::{Cookie, SameSite, time::Duration};
  2. pub fn create_cookie(name: String, value: String) -> Cookie<'static> {
  3. if cfg!(debug_assertions){
  4. Cookie::build(name, value)
  5. .path("/")
  6. .http_only(true)
  7. .same_site(SameSite::Lax)
  8. .secure(false)
  9. .max_age(Duration::days(90))
  10. .finish()
  11. } else {
  12. Cookie::build(name, value)
  13. .domain("exmaple.com")
  14. .path("/")
  15. .http_only(true)
  16. .same_site(SameSite::Lax)
  17. .secure(true)
  18. .max_age(Duration::days(90))
  19. .finish()
  20. }
  21. }