fix(users): revert using mget in authorization (#3999)

This commit is contained in:
Mani Chandra
2024-03-07 13:37:18 +05:30
committed by GitHub
parent 6671bff3b1
commit 7375b866a2

View File

@ -80,25 +80,19 @@ pub async fn check_user_in_blacklist<A: AppStateInfo>(
.map(|timestamp| timestamp.map_or(false, |timestamp| timestamp > token_issued_at))
}
pub async fn check_user_and_role_in_blacklist<A: AppStateInfo>(
pub async fn check_role_in_blacklist<A: AppStateInfo>(
state: &A,
user_id: &str,
role_id: &str,
token_expiry: u64,
) -> RouterResult<bool> {
let user_token = format!("{}{}", USER_BLACKLIST_PREFIX, user_id);
let role_token = format!("{}{}", ROLE_BLACKLIST_PREFIX, role_id);
let token = format!("{}{}", ROLE_BLACKLIST_PREFIX, role_id);
let token_issued_at = expiry_to_i64(token_expiry - JWT_TOKEN_TIME_IN_SECS)?;
let redis_conn = get_redis_connection(state)?;
Ok(redis_conn
.get_multiple_keys::<Vec<&str>, i64>(vec![user_token.as_str(), role_token.as_str()])
redis_conn
.get_key::<Option<i64>>(token.as_str())
.await
.change_context(ApiErrorResponse::InternalServerError)?
.into_iter()
.max()
.flatten()
.map_or(false, |timestamp| timestamp > token_issued_at))
.change_context(ApiErrorResponse::InternalServerError)
.map(|timestamp| timestamp.map_or(false, |timestamp| timestamp > token_issued_at))
}
#[cfg(feature = "email")]
@ -156,7 +150,10 @@ impl BlackList for AuthToken {
where
A: AppStateInfo + Sync,
{
check_user_and_role_in_blacklist(state, &self.user_id, &self.role_id, self.exp).await
Ok(
check_user_in_blacklist(state, &self.user_id, self.exp).await?
|| check_role_in_blacklist(state, &self.role_id, self.exp).await?,
)
}
}