-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial refactor to axum 0.6 * modified how state is used with Store for Axum 0.6 * comments and cargo fmt * updated readme
- Loading branch information
Showing
9 changed files
with
293 additions
and
215 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
use axum::{ | ||
extract::RequestParts, | ||
http::{Request, StatusCode}, | ||
middleware::Next, | ||
response::Response, | ||
}; | ||
use axum_sessions::extractors::ReadableSession; | ||
|
||
#[allow(clippy::missing_errors_doc)] | ||
pub async fn user_secure<B: Send>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> { | ||
pub async fn user_secure<B: Send>( | ||
session: ReadableSession, | ||
req: Request<B>, | ||
next: Next<B>, | ||
) -> Result<Response, StatusCode> { | ||
tracing::info!("Middleware: checking if user exists"); | ||
let mut request_parts = RequestParts::new(req); | ||
let session = request_parts | ||
.extract::<ReadableSession>() | ||
.await | ||
.map_err(|_| StatusCode::UNAUTHORIZED)?; | ||
let user_id = session.get_raw("user_id").ok_or(StatusCode::UNAUTHORIZED)?; | ||
tracing::debug!("user_id Extracted: {}", user_id); | ||
|
||
// accepts all user but you could add a check here to match user access | ||
|
||
let req = request_parts.try_into_request().expect("body extracted"); | ||
Ok(next.run(req).await) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters