1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

add session ttl customization example

This commit is contained in:
Rob Ede
2022-08-28 18:39:28 +01:00
parent d259177eab
commit fcd013fcde
18 changed files with 84 additions and 60 deletions

View File

@ -5,8 +5,14 @@
//!
//! [User guide](https://actix.rs/docs/middleware/#user-sessions)
use actix_session::{storage::CookieSessionStore, Session, SessionMiddleware};
use actix_web::{cookie::Key, middleware::Logger, web, App, HttpRequest, HttpServer, Result};
use actix_session::{
config::PersistentSession, storage::CookieSessionStore, Session, SessionMiddleware,
};
use actix_web::{
cookie::{self, Key},
middleware::Logger,
web, App, HttpRequest, HttpServer, Result,
};
/// simple index handler with session
async fn index(session: Session, req: HttpRequest) -> Result<&'static str> {
@ -39,6 +45,10 @@ async fn main() -> std::io::Result<()> {
.wrap(
SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&[0; 64]))
.cookie_secure(false)
// customize session and cookie expiration
.session_lifecycle(
PersistentSession::default().session_ttl(cookie::time::Duration::hours(2)),
)
.build(),
)
.service(web::resource("/").to(index))