use axum::{
Json,
extract::{Path, State},
response::{IntoResponse, Response},
};
use crate::routes::{graphql::app_state::AppState, studio::not_implemented};
pub async fn revoke_user_handler(
Path(user_id): Path<String>,
State(state): State<AppState>,
) -> Response {
let Some(manager) = state.revocation_manager.as_ref() else {
return not_implemented(
"studio.users.revoke",
"Token revocation is not configured, so no session can be revoked. Enable \
[security.token_revocation] in fraiseql.toml.",
);
};
match manager.revoke_all_for_user(&user_id).await {
Ok(()) => Json(serde_json::json!({
"success": true,
"user_id": user_id,
"message": "All sessions revoked",
}))
.into_response(),
Err(e) => {
tracing::error!(error = %e, user = %user_id, "revoke-all failed");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({
"error": "revocation_failed",
"message": "The revocation store rejected the write; sessions are NOT revoked.",
})),
)
.into_response()
},
}
}