diff --git a/meilisearch-auth/src/lib.rs b/meilisearch-auth/src/lib.rs index 35532e0c4..a0c94ce44 100644 --- a/meilisearch-auth/src/lib.rs +++ b/meilisearch-auth/src/lib.rs @@ -175,8 +175,13 @@ impl AuthController { self.store.list_api_keys() } - pub fn delete_key(&self, uid: Uuid) -> Result<()> { - if self.store.delete_api_key(uid)? { + pub async fn delete_key(&self, uid: Uuid) -> Result<()> { + let store = self.store.clone(); + let deleted = tokio::task::spawn_blocking(move || store.delete_api_key(uid)).await??; + if deleted { + if let Some(ref zk) = self.zk { + zk.delete(&format!("/auth/{}", uid), None).await?; + } Ok(()) } else { Err(AuthControllerError::ApiKeyNotFound(uid.to_string())) diff --git a/meilisearch/src/routes/api_key.rs b/meilisearch/src/routes/api_key.rs index 834750e64..0caa4e0f0 100644 --- a/meilisearch/src/routes/api_key.rs +++ b/meilisearch/src/routes/api_key.rs @@ -118,13 +118,8 @@ pub async fn delete_api_key( path: web::Path, ) -> Result { let key = path.into_inner().key; - tokio::task::spawn_blocking(move || { - let uid = - Uuid::parse_str(&key).or_else(|_| auth_controller.get_uid_from_encoded_key(&key))?; - auth_controller.delete_key(uid) - }) - .await - .map_err(|e| ResponseError::from_msg(e.to_string(), Code::Internal))??; + let uid = Uuid::parse_str(&key).or_else(|_| auth_controller.get_uid_from_encoded_key(&key))?; + auth_controller.delete_key(uid).await?; Ok(HttpResponse::NoContent().finish()) }