Fix: add FromRequestParts impl for security AuthenticatedUser extractor
All checks were successful
BotServer CI / build (push) Successful in 11m32s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-03-16 22:04:59 -03:00
parent 49e9f419f3
commit c0b619b58f

View file

@ -489,3 +489,25 @@ impl AuthenticatedUser {
.collect() .collect()
} }
} }
#[axum::async_trait]
impl<S> axum::extract::FromRequestParts<S> for AuthenticatedUser
where
S: Send + Sync,
{
type Rejection = (axum::http::StatusCode, axum::Json<serde_json::Value>);
async fn from_request_parts(
parts: &mut axum::http::request::Parts,
_state: &S,
) -> Result<Self, Self::Rejection> {
parts
.extensions
.get::<AuthenticatedUser>()
.cloned()
.ok_or((
axum::http::StatusCode::UNAUTHORIZED,
axum::Json(serde_json::json!({"error": "Authentication required"})),
))
}
}