DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.47k stars 786 forks source link

`axum-auth` example fails with `ServerError("AuthSessionLayer was not found")` #2094

Closed kaivol closed 2 months ago

kaivol commented 6 months ago

Problem

The axum-auth fullstack example fails with called `Result::unwrap()` on an `Err` value: ServerError("AuthSessionLayer was not found") when clicking the Login Test User button.

I suspect that this is caused by an incorrect handling of the DioxusServerContext. Debugging shows that the map returned by server_context().request_parts_mut().await.extensions (in the login() server function) is empty. The following diff (https://github.com/DioxusLabs/dioxus/commit/27a2237d09744e99514e6a41481ca75caebb5401) seems to fix the issue, but I'm not sure if that is the correct approach:

@@ -483,7 +483,7 @@ async fn handle_server_fns_inner(
             let referrer = req.headers().get(REFERER).cloned();

             // actually run the server fn
-            let mut res = service.run(req).await;
+            let mut res = ProvideServerContext::new(service.run(req), server_context.clone()).await;

Steps To Reproduce

Steps to reproduce the behavior:

Environment:

Questionnaire

jkelleyrtp commented 2 months ago

Fixed by #2139