add dep on sqlite backend for session store

This commit is contained in:
Joe Ardent 2024-03-04 22:21:08 -08:00
parent 8e25651cfa
commit d589a88c30
3 changed files with 878 additions and 20 deletions

886
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -17,10 +17,12 @@ passwords = { version = "3", default-features = false }
rand = { version = "0.8", default-features = false, features = ["getrandom"] } rand = { version = "0.8", default-features = false, features = ["getrandom"] }
serde = { version = "1", default-features = false, features = ["derive"] } serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1", default-features = false } serde_json = { version = "1", default-features = false }
sqlx = { version = "0.7", default-features = false, features = ["runtime-tokio", "sqlite", "tls-none", "migrate"] }
thiserror = { version = "1" } thiserror = { version = "1" }
time = { version = "0.3", default-features = false } time = { version = "0.3", default-features = false }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] } tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
tower-http = { version = "0.5", default-features = false, features = ["fs"] } tower-http = { version = "0.5", default-features = false, features = ["fs"] }
tower-sessions = { version = "0.10", default-features = false, features = ["axum-core", "memory-store"] } tower-sessions = { version = "0.11", default-features = false, features = ["axum-core"] }
tower-sessions-sqlx-store = { version = "0.11.0", default-features = false, features = ["sqlite"] }
unicode-segmentation = { version = "1", default-features = false } unicode-segmentation = { version = "1", default-features = false }
ureq = { version = "2", default-features = false, features = ["json", "tls"] } ureq = { version = "2", default-features = false, features = ["json", "tls"] }

View file

@ -10,7 +10,8 @@ use axum::{
}; };
use tokio::net::TcpListener; use tokio::net::TcpListener;
use tower_http::services::ServeDir; use tower_http::services::ServeDir;
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer}; use tower_sessions::{Expiry, SessionManagerLayer};
use tower_sessions_sqlx_store::{sqlx::SqlitePool, SqliteStore};
#[macro_use] #[macro_use]
extern crate justerror; extern crate justerror;
@ -28,11 +29,14 @@ async fn main() {
init(); init();
// for javascript and css // for javascript and css
// TODO: figure out how to intern these contents
let assets_dir = std::env::current_dir().unwrap().join("assets"); let assets_dir = std::env::current_dir().unwrap().join("assets");
let assets_svc = ServeDir::new(assets_dir.as_path()); let assets_svc = ServeDir::new(assets_dir.as_path());
// just for signups // just for signups
let session_store = MemoryStore::default(); let pool = SqlitePool::connect("sqlite:memory:").await.unwrap();
let session_store = SqliteStore::new(pool);
session_store.migrate().await.unwrap();
let session_layer = SessionManagerLayer::new(session_store) let session_layer = SessionManagerLayer::new(session_store)
.with_secure(false) .with_secure(false)
.with_same_site(tower_sessions::cookie::SameSite::Lax) .with_same_site(tower_sessions::cookie::SameSite::Lax)