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:
parent
02e6c4145e
commit
c0f5908089
28
server-api/db/src/auth.rs
Normal file
28
server-api/db/src/auth.rs
Normal 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)
|
||||
}
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user