diff --git a/server-api/db/src/auth.rs b/server-api/db/src/auth.rs new file mode 100644 index 0000000..aeba8ec --- /dev/null +++ b/server-api/db/src/auth.rs @@ -0,0 +1,28 @@ +use crate::UBigInt; + +use redis::{ + Client, AsyncCommands, + RedisResult +}; + +lazy_static! { + static ref REDIS_URL: String = { + std::env::var("REDIS_URL").unwrap() + }; +} + +pub async fn add_jwt(id: UBigInt, token: &str) -> RedisResult<()> { + let client = Client::open(REDIS_URL.as_ref())?; + let mut conn = client.get_tokio_connection().await?; + + let _ = conn.set(id, token).await?; + Ok(()) +} + +pub async fn active_jwt(id: UBigInt, token: &str) -> RedisResult { + let client = Client::open(REDIS_URL.as_ref())?; + let mut conn = client.get_tokio_connection().await?; + + let val: String = conn.get(id).await?; + Ok(val == token) +} \ No newline at end of file diff --git a/server-api/db/src/lib.rs b/server-api/db/src/lib.rs index 914b576..37310e4 100644 --- a/server-api/db/src/lib.rs +++ b/server-api/db/src/lib.rs @@ -1,9 +1,12 @@ +#[macro_use] extern crate lazy_static; + extern crate serde; pub mod member; pub mod common; pub mod invites; pub mod channels; pub mod messages; +pub mod auth; use std::vec::Vec;