Store sessions in redis

This commit is contained in:
2023-09-26 01:47:50 -04:00
parent 306059c355
commit 6fd2f150a0
5 changed files with 370 additions and 22 deletions

View File

@@ -7,6 +7,8 @@ pub struct Config {
#[clap(long, env)]
pub database_max_connections: u32,
#[clap(long, env)]
pub redis_url: String,
#[clap(long, env)]
pub host: String,
#[clap(long, env)]
pub port: u16,

View File

@@ -1,13 +1,14 @@
use std::{collections::HashMap, net::SocketAddr, path::Path, sync::Arc};
use anyhow::Result;
use async_redis_session::RedisSessionStore;
use axum::{
response::IntoResponse,
routing::{get, post},
Extension, Router,
};
use axum_login::{
axum_sessions::{async_session::MemoryStore, SessionLayer},
axum_sessions::SessionLayer,
AuthLayer, PostgresStore, RequireAuthorizationLayer,
};
use bytes::Bytes;
@@ -71,8 +72,7 @@ async fn main() -> Result<()> {
.connect(&config.database_url)
.await?;
// TODO: store sessions in postgres eventually
let session_store = MemoryStore::new();
let session_store = RedisSessionStore::new(config.redis_url.clone())?;
let session_layer = SessionLayer::new(session_store, &secret).with_secure(false);
let user_store = PostgresStore::<User>::new(pool.clone())
.with_query("select * from users where user_id = $1");