Add identity and session middlewares
This commit is contained in:
parent
8f9d7b5bc5
commit
960d0d4662
16
src/main.rs
16
src/main.rs
@ -11,9 +11,23 @@ extern crate diesel;
|
|||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
use actix_identity::IdentityMiddleware;
|
||||||
|
use actix_session::storage::RedisSessionStore;
|
||||||
|
use actix_session::SessionMiddleware;
|
||||||
|
use actix_web::cookie::Key;
|
||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
|
let session_secret_key = if let Ok(key) = std::env::var("SESSION_SECRET_KEY") {
|
||||||
|
Key::from(key.as_bytes())
|
||||||
|
} else {
|
||||||
|
Key::generate()
|
||||||
|
};
|
||||||
|
|
||||||
|
let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set");
|
||||||
|
let redis_store = RedisSessionStore::new(redis_url).await.unwrap();
|
||||||
|
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
@ -40,6 +54,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(favicon)
|
.service(favicon)
|
||||||
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), App)
|
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), App)
|
||||||
.app_data(web::Data::new(leptos_options.to_owned()))
|
.app_data(web::Data::new(leptos_options.to_owned()))
|
||||||
|
.wrap(IdentityMiddleware::default())
|
||||||
|
.wrap(SessionMiddleware::new(redis_store.clone(), session_secret_key.clone()))
|
||||||
//.wrap(middleware::Compress::default())
|
//.wrap(middleware::Compress::default())
|
||||||
})
|
})
|
||||||
.bind(&addr)?
|
.bind(&addr)?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user