Replies: 3 comments 7 replies
-
chatgpt gave me some suggestions on how to get axum middleware to work with server functions. I didn't include it in the description above though as it appears to be complete nonsense. If I said anything that appears to be wrong, please feel free to correct me :-) |
Beta Was this translation helpful? Give feedback.
-
OK, so the middleware does work when calling the server functions manually. But when calling the server functions from the app, dioxus somehow does it in such a way to bypass the axum middleware. Not sure I understand really. |
Beta Was this translation helpful? Give feedback.
-
I found a I can call I can include a call to But the moment I try to await on the future, and this is included in a server function, suddenly rust complains that it can't use the axum Handler trait for the server function. Doesn't matter if the extract is directly in the server function, or if the server function calls a helper function that calls extract, or if there is any number of nested calls. This is kind of weird. I note FullstackContext is based on Rc values, wonder if this is somehow the problem. Async code on Tokio may require Arc. Unfortunately the extract method is async, so I have to call it from async code. Oh well, I guess this isn't the solution I hoped it might be. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How do I store and retrieve global state, e.g. database handle?
Previously I added an axum extension:
And I would use the
extract()
method to get the global value.But seems 0.7.0-rc.2 no longer has the extract() method.
Instead the new way is to add a parameter to the server function:
(this is from memory, apologizes if I got it wrong)
(actually not 100% sure this is exactly correct, blame chatgpt; I see an example that adds the parameter to the macro not the function)
But this has two limitations:
The existing code - which I don't quite understand 100% that deals with axum-login is this:
Somehow this makes it so that the
extract()
function will work on Session values. I am not really clear what the state parameter is.So chatgpt, always trying to be helpful suggested that I set a
task_local!
state inside some axum middleware, and use that to replace the missing extract() function. I also have axum middleware that will put the axum-login session in an extension.And add to the axum router above:
Problem here is that - to the best of my knowledge - axum middleware is not called for server functions. Or if it is,
REQ_EXTENSIONS
is not set inside the server functions for some other reason.So I thought I probably should ask here for help.
Beta Was this translation helpful? Give feedback.
All reactions