-
SummaryI'm trying to create a middleware that needs access to my app state. Following the documentation, the signature of my middleware is pub async fn required_role(
State(state): State<AppState>,
headers: HeaderMap,
request: Request,
next: Next,
) -> Response I'm adding it to my router like this let axum_response = axum::Router::new()
.route("/v0/test", get(|| async { "Hello from axum router" }))
.route_layer(axum::middleware::from_fn_with_state(
app_state.clone(),
middleware::required_role,
))
.with_state(app_state)
.call(axum_request) // tower_service::Service
.await?; This is the error I get:
The issue seems to be related to the Any help would appreciated. axum version0.7.4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The problem is that inside my middleware I'm holding as |
Beta Was this translation helpful? Give feedback.
The problem is that inside my middleware I'm holding as
!Send
type across an await point. I figured this out by using the#[axum_macros::debug_handler]
macro.