From f6d103da57273752b6025c2be00cc0928e2d03c2 Mon Sep 17 00:00:00 2001 From: "Takahiro, NAKAMURA" <4410504+na9amura@users.noreply.github.com> Date: Wed, 26 Oct 2022 19:14:06 +0900 Subject: [PATCH] update user_session sample (#292) --- examples/middleware/Cargo.toml | 2 +- examples/middleware/src/user_sessions.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/middleware/Cargo.toml b/examples/middleware/Cargo.toml index bfd1b52..6d68402 100644 --- a/examples/middleware/Cargo.toml +++ b/examples/middleware/Cargo.toml @@ -5,6 +5,6 @@ edition = "2018" [dependencies] actix-web = "4" -actix-session = "0.5.0-beta.8" +actix-session = { version = "0.7.2", features = ["cookie-session"] } futures-util = { version = "0.3.7", default-features = false, features = ["std"] } env_logger = "0.7" diff --git a/examples/middleware/src/user_sessions.rs b/examples/middleware/src/user_sessions.rs index b570537..d708ea0 100644 --- a/examples/middleware/src/user_sessions.rs +++ b/examples/middleware/src/user_sessions.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] // -use actix_session::{CookieSession, Session}; -use actix_web::{web, App, Error, HttpResponse, HttpServer}; +use actix_session::{Session, SessionMiddleware, storage::CookieSessionStore}; +use actix_web::{web, App, Error, HttpResponse, HttpServer, cookie::Key}; async fn index(session: Session) -> Result { // access session data @@ -23,8 +23,10 @@ async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .wrap( - CookieSession::signed(&[0; 32]) // <- create cookie based session middleware - .secure(false), + // create cookie based session middleware + SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&[0; 64])) + .cookie_secure(false) + .build() ) .service(web::resource("/").to(index)) })