+ Jwt tables - SEE NOTE
! wat - because have to do maintain permissions on a per request level we have to do this check for permissions at what is basically every level, this does mean we have to hit the database for a lot of routes however there is a check that requests go through in order to avoid hitting the database whenever possible + rng field in claims now has real purpose It's purpose is to act as a validator field in the jwt table. By verifying rng fields we no longer have to store whole jwt's
This commit is contained in:
19
json-api/db/src/jwt.rs
Normal file
19
json-api/db/src/jwt.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use mysql_async::{Pool, params, Result, prelude::Queryable};
|
||||
|
||||
pub async fn listed(p: &Pool, id: u64, given_rng_value: &str) -> Result<bool> {
|
||||
let mut conn = p.get_conn().await?;
|
||||
let q = "SELECT rng FROM jwt WHERE id = :id";
|
||||
let row: Option<String> = conn.exec_first(q, params!{"id" => id}).await?;
|
||||
if let Some(value) = row {
|
||||
Ok(value == given_rng_value)
|
||||
} else{
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn insert(p: &Pool, id: u64, given_rng_value: &str) -> Result<()> {
|
||||
let mut conn = p.get_conn().await?;
|
||||
let q = "INSERT INTO jwt (id, rng) VALUES (:id, :rng)";
|
||||
conn.exec_drop(q, params!{"id" => id, "rng" => given_rng_value}).await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -6,6 +6,7 @@ pub mod invites;
|
||||
pub mod channels;
|
||||
pub mod messages;
|
||||
pub mod neighbors;
|
||||
pub mod jwt;
|
||||
|
||||
use std::vec::Vec;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user