Replies: 2 comments 1 reply
-
Hi -- Sorry for the delayed response. I don't have enough experience with Axum extensions or middleware to know whether extensions would behave differently from any other extractor in this situation. That said, the error message here doesn't have to do with the extractor itself, and it would actually bail out before the extractor even runs. I have not seen reports of similar issues, so you may be looking in the wrong place. (For example, are you using a custom handler or something similar that doesn't provide I'm happy to look at a minimal reproduction at some point if you have one, but I don't think there's much more I can say than the above for now. |
Beta Was this translation helpful? Give feedback.
-
Good day, Here is a functional version of what I am attempting to do with leptos, but solely in Axum. To take note that the handler is using Extension as a parameter here, in place of using the extract::<Extension>() utility. From what I can gather, you suggest that I implement FromRequestParts for User ? use axum::extract::Request;
use axum::http::StatusCode;
use axum::middleware::Next;
use axum::response::Response;
use axum::routing::get;
use axum::{middleware, Extension, Router};
// Required to be passed by Extension
#[derive(Clone)]
struct User(&'static str);
// Middleware doing some authentication
async fn auth(mut request: Request, next: Next) -> Result<Response, StatusCode>{
// Passing the user to the handler
request.extensions_mut().insert(User("current user"));
Ok(next.run(request).await)
}
async fn handler(
// Getting the user from the middleware
Extension(current_user): Extension<User>,
) {
println!("Hello, {:?}!", current_user.0);
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(handler))
.route_layer(middleware::from_fn(auth));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();
axum::serve(listener, app.into_make_service()).await.unwrap();
} Again, thank you for your time and no worries for the delays . |
Beta Was this translation helpful? Give feedback.
-
Good day,
I looked everywhere I could, but could not find an answer.
Hopefully this is a problem on my side and not one on the framework, or its already fixed in 7.1.
I am attempting to retrieve in a handler a user that was extracted from my database in my middlewear.
In axum I could do it this way (per their documentation) :
So, based on this example and the section on extractors in the leptos book, I would expect this pattern to work.
What I get as a result is : "should have had Parts provided by the leptos_axum integration" that I can be found in :
leptos/integrations/axum/src/lib.rs
Line 1972 in f9533ab
Am I missing something ?
Thanks for your time,
Beta Was this translation helpful? Give feedback.
All reactions