Closed TxMat closed 9 months ago
You can just use extractors in your middleware
For anyone wondering what this means, you can just do this:
pub async fn auth<B>(
State(state): State<AuthMiddlewareState>,
client_ip: InsecureClientIp,
config: ConfigExt,
req: Request<B>,
next: Next<B>,
) -> Result<Response, MyError> {
This is with Axum 0.6. If you get an error with this, make sure you're using the version of this library that corresponds with the version of Axum you're using. For example, 0.4.2 of axum-client-ip for axum version 0.6. Also make sure you've registered your app like this:
app.into_make_service_with_connect_info::<SocketAddr>()
Oops, forgot to close the issue !
Thanks to both of you.
I need to auth clients based on their IPs on every request so i just thought about using axum middleware but it seems that the client IP is inaccessible from this scope. Am I doing it wrong ? Is it already supported ?
Thanks !