poem
poem copied to clipboard
how to create fn middleware with state?
Is there a way to create a fn middleware with state? Something similar to https://docs.rs/axum/latest/axum/middleware/fn.from_fn_with_state.html . Use case is a custom middleware that does some auth checking and needs access to a database.
I know I can use .data to add state to a handler but the same technique doesn't appear to work for middleware fns.
You can get it from request with .extensions().get() one you add it to the router.
https://docs.rs/poem/1.3.55/poem/struct.Request.html#method.extensions