diff --git a/backend/src/web/mw_auth.rs b/backend/src/web/mw_auth.rs index 4df22ae..3cc3720 100644 --- a/backend/src/web/mw_auth.rs +++ b/backend/src/web/mw_auth.rs @@ -5,13 +5,14 @@ use axum::{ }; use tower_cookies::Cookies; -use crate::{ctx::Ctx, error::LoftError, model::UserRepository, web::AUTH_TOKEN}; +use crate::{ + ctx::Ctx, + error::{LoftError, Result}, + model::UserRepository, + web::AUTH_TOKEN, +}; -pub async fn mw_require_auth( - ctx: Result, - req: Request, - next: Next, -) -> Result { +pub async fn mw_require_auth(ctx: Result, req: Request, next: Next) -> Result { ctx?; Ok(next.run(req).await) @@ -22,7 +23,7 @@ pub async fn mw_ctx_resolver( cookies: Cookies, mut req: Request, next: Next, -) -> Result { +) -> Result { let auth_token = cookies.get(AUTH_TOKEN).map(|c| c.value().to_string()); let result_ctx = match auth_token { @@ -46,7 +47,7 @@ impl FromRequestParts for Ctx { ) -> Result { parts .extensions - .get::>() + .get::>() .ok_or(LoftError::AuthFailCtxNotInRequestExt)? .clone() } diff --git a/backend/src/web/routes_file.rs b/backend/src/web/routes_file.rs index bda0f54..1d4bb87 100644 --- a/backend/src/web/routes_file.rs +++ b/backend/src/web/routes_file.rs @@ -27,7 +27,7 @@ async fn upload_file( State(file_repository): State, ctx: Ctx, mut multipart: Multipart, -) -> Result, LoftError> { +) -> Result> { let mut uploaded: Option<(String, String, usize)> = None; while let Some(field) = multipart.next_field().await? { @@ -52,7 +52,7 @@ async fn get_file( State(file_repository): State, ctx: Ctx, Path(file_id): Path, -) -> Result, LoftError> { +) -> Result> { let record = file_repository .get_file(file_id as i64, ctx.user_id()) .await?; @@ -121,7 +121,7 @@ async fn delete_file( State(file_repository): State, ctx: Ctx, Path(file_id): Path, -) -> Result, LoftError> { +) -> Result> { let file = file_repository .delete_file(file_id as i64, ctx.user_id()) .await?; @@ -131,7 +131,7 @@ async fn delete_file( async fn list_files( State(file_repository): State, ctx: Ctx, -) -> Result>, LoftError> { +) -> Result>> { let files = file_repository.list_files(ctx.user_id()).await?; Ok(Json(files)) } diff --git a/backend/src/web/routes_login.rs b/backend/src/web/routes_login.rs index a2faf31..dfdb843 100644 --- a/backend/src/web/routes_login.rs +++ b/backend/src/web/routes_login.rs @@ -26,7 +26,7 @@ async fn login( State(user_repository): State, cookies: Cookies, Json(payload): Json, -) -> Result { +) -> Result { let user = user_repository .find_by_username(&payload.username) .await? @@ -53,7 +53,7 @@ async fn login( async fn logout( State(user_repository): State, cookies: Cookies, -) -> Result { +) -> Result { let auth_token = cookies.get(AUTH_TOKEN).map(|c| c.value().to_string()); if let Some(auth_token) = auth_token { @@ -67,7 +67,7 @@ async fn logout( async fn register( State(user_repository): State, Json(payload): Json, -) -> Result { +) -> Result { if user_repository .find_by_username(&payload.username) .await?