aboutsummaryrefslogtreecommitdiffstats
path: root/lib/auth-service/src/service/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/auth-service/src/service/mod.rs')
-rw-r--r--lib/auth-service/src/service/mod.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/auth-service/src/service/mod.rs b/lib/auth-service/src/service/mod.rs
index 3d45523..5150221 100644
--- a/lib/auth-service/src/service/mod.rs
+++ b/lib/auth-service/src/service/mod.rs
@@ -1,17 +1,20 @@
use async_session::{Result, Session, SessionStore};
use async_trait::async_trait;
-use shared_svc::cache::RedisManager;
-use tracing::instrument;
+use shared_svc::cache::{CacheKey, RedisManager, redis::AsyncCommands};
+use sqlx::PgPool;
+use tracing::{debug, instrument};
#[derive(Debug, Clone)]
pub struct AuthService {
cache: RedisManager,
+ database: PgPool,
}
impl AuthService {
- pub fn new(cache: &RedisManager) -> Self {
+ pub fn new(cache: &RedisManager, database: &PgPool) -> Self {
Self {
cache: cache.clone(),
+ database: database.clone(),
}
}
}
@@ -32,20 +35,32 @@ impl SessionStore for AuthService {
#[doc = ""]
#[doc = " The return value is the value of the cookie to store for the"]
#[doc = " user that represents this session"]
- #[instrument(skip(self))]
+ #[instrument(err(Debug), skip(self, session), fields(id = session.id()))]
async fn store_session(&self, session: Session) -> Result<Option<String>> {
- todo!()
+ debug!("storing session");
+ let mut client = self.cache.get().await?;
+ let bytes = serde_json::to_vec(&session)?;
+ client
+ .set_ex::<_, _, ()>(CacheKey::Session(session.id()), bytes, 3600)
+ .await?;
+ Ok(session.into_cookie_value())
}
#[doc = " Remove a session from the session store"]
- #[instrument(skip(self))]
+ #[instrument(err(Debug), skip(self, session), fields(id = session.id()))]
async fn destroy_session(&self, session: Session) -> Result {
- todo!()
+ debug!("destroying session");
+ let mut client = self.cache.get().await?;
+ client.del::<_, ()>(CacheKey::Session(session.id())).await?;
+ Ok(())
}
#[doc = " Empties the entire store, destroying all sessions"]
#[instrument(skip(self))]
async fn clear_store(&self) -> Result {
- todo!()
+ debug!("clearing store");
+ let mut client = self.cache.get().await?;
+ client.del::<_, ()>(CacheKey::Session("").key()).await?;
+ Ok(())
}
}