version 0.7.3 middleleware next takes struct takes 0 generic arguments #2488
-
I use axum which version is 0.73 to developer interceptor and an error occured:
here are my interceptor code use axum::{
middleware::Next,
http::Request,
response::IntoResponse,
Json
};
use crate::{
config::custom_authorization_error,
utils::jwt,
db::rget,
};
/**
* @desc custome request headers
*/
pub async fn verify_auth<B>(
request: Request<B>,
next: Next<B>,
) -> impl IntoResponse {
if request.headers().contains_key("Authorization") {
let token_bare = request.headers().get("Authorization")
.unwrap().
to_str().
unwrap();
let jwt_token = token_bare.trim_start_matches("Bearer ");
let jwt_claims_id = match jwt::verify(jwt_token) {
Ok(res) => {
res.sub
},
Err(_err) => {
"".to_string()
}
};
if jwt_token.is_empty() {
return Json(custom_authorization_error()).into_response()
}
let user_token_key = format!("token:{}",jwt_claims_id);
let login_token_string: String = rget(&user_token_key).unwrap();
if login_token_string.is_empty() {
return Json(custom_authorization_error()).into_response()
}
// pass
next.run(request).await
} else {
// failed
Json(custom_authorization_error()).into_response()
}
}
``
and here are part of my Cargo.toml
```toml
[dependencies]
axum = "0.7.3"
askama = "0.12.1"
axum-macros = "0.4.0"
axum-extra = "0.9.1" I don't know how to solve it. |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Jan 3, 2024
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jplatte
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Next
doesn't take any type parameters in 0.7. See the docs and changelog.