Tiny auth module for literally just redis and jwt things

Also we're doing a really budget version of sessions here so we might change things later but this is fine for now
This commit is contained in:
shockrah 2020-12-22 21:30:35 -08:00
parent 02e6c4145e
commit c0f5908089
2 changed files with 31 additions and 0 deletions

28
server-api/db/src/auth.rs Normal file
View File

@ -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<bool> {
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)
}

View File

@ -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;