feat: admin provider routes (list/update/delete/test) with admin middleware

This commit is contained in:
2026-03-16 03:34:54 +01:00
parent 46333853d2
commit 87f94fcc51
3 changed files with 380 additions and 0 deletions

View File

@@ -78,6 +78,21 @@ impl FromRequestParts<AppState> for OptionalCurrentUser {
}
}
/// Extracted admin user — returns 403 if user is not an admin.
pub struct AdminUser(pub User);
impl FromRequestParts<AppState> for AdminUser {
type Rejection = ApiError;
async fn from_request_parts(parts: &mut Parts, state: &AppState) -> Result<Self, Self::Rejection> {
let CurrentUser(user) = CurrentUser::from_request_parts(parts, state).await?;
if !user.is_admin {
return Err(ApiError::Forbidden("Admin access required".to_string()));
}
Ok(AdminUser(user))
}
}
/// Authenticate using JWT Bearer token from the `Authorization` header.
#[cfg(feature = "auth-jwt")]
async fn try_jwt_auth(parts: &mut Parts, state: &AppState) -> Result<User, ApiError> {