Dioxus 0.6 authentication and extractors #3414
Replies: 1 comment 5 replies
-
At the axum level (not sure if this helps or not), you set up middle ware to do the authentication "the way you want"(tm). Example is a bit different from the above example because that uses the This will set an Axum extension using something like: request.extensions_mut().insert(user); And use that value to call inner layers: let mut response = inner.call(request).await?; I think you are using full stack. So presumably you will want the component to have access to the user too. You can do this via a server function: [server(MagicNumber)]
async fn user() -> Result<u32, ServerFnError> {
let Extension(user) = extract::<Extension<user>, _>().await?;
Ok(user)
} And the component can look something like: [component]
fn DisplayUser() -> Element {
let user = use_resource(user);
rsx! {
div {
match &*user.read() {
Some(Ok(user)) => {
rsx! {
p { "User: {u ser}" }
}
}
Some(Err(err)) => {
rsx! {
p { "Error loading your user: {err}." }
}
}
None => {
rsx! {
p { "Loading user..." }
}
}
}
p { "Segments: {segments}" }
}
}
} Disclaimer: Not tested but copied and pasted from code that was working :-). However I just learnt you can use the extract function to retrieve axum extensions. I didn't know that. Cool! |
Beta Was this translation helpful? Give feedback.
-
I'm a bit lost on how to use extractors correctly with 0.6 without replicating the whole
launch
function body fromdioxus_fullstack
.The documentation still links to the 0.5 tag: https://github.com/DioxusLabs/dioxus/blob/v0.5/packages/fullstack/examples/axum-auth/src/main.rs
Is there any way to pass layers to the
LaunchBuilder
or do we really need to replicate everything from here for now?Beta Was this translation helpful? Give feedback.
All reactions