diff --git a/reqtasks/src/lib.rs b/reqtasks/src/lib.rs index 643d986..81a78cd 100644 --- a/reqtasks/src/lib.rs +++ b/reqtasks/src/lib.rs @@ -363,6 +363,24 @@ impl ReqTasks { pub async fn user_authentication(&self) -> anyhow::Result { let token = self.token_from_header().unwrap_or_else(|e| { println!("{}",e); String::from("")}); self.check_authentication(token).await + } + #[allow(clippy::missing_errors_doc)] + pub async fn user_role(&self) -> String { + let token = self.token_from_header().unwrap_or_else(|e| { println!("{}",e); String::from("")}); + if token.is_empty() { + return String::from(""); + } + let role: String; + if let Some(user_id) = self.auth_store.sessions.read().await.get(&token) { + if let Some(user) = self.auth_store.users.read().await.get(user_id) { + role = format!("{}",user.role); + } else { + role = String::from(""); + } + } else { + role = String::from(""); + } + role } #[allow(clippy::missing_errors_doc)] pub async fn check_authentication(&self, token: String) -> anyhow::Result {