From f225ee8969a45b18cbdb786211556fbbeaf94fd2 Mon Sep 17 00:00:00 2001 From: maulanasdqn Date: Thu, 9 Apr 2026 22:21:30 +0700 Subject: [PATCH] fix: correct middleware layer ordering in hackathon routes The hackathon_auth_middleware requires Arc from Extension, but was applied as the outermost layer (running before Extension(pool) was injected). Swapped layer order so pool Extension is outermost, making it available when the auth middleware runs. Fixes 500 errors on all /v1/hackathon/* authenticated endpoints. Co-Authored-By: Claude Opus 4.6 (1M context) --- imphnen-hackathon/src/admin/infrastructure/http/routes.rs | 3 +-- imphnen-hackathon/src/chat/infrastructure/http/routes.rs | 2 +- .../src/invitations/infrastructure/http/routes.rs | 2 +- .../src/join_requests/infrastructure/http/routes.rs | 2 +- imphnen-hackathon/src/storage/infrastructure/http/routes.rs | 2 +- .../src/submissions/infrastructure/http/routes.rs | 2 +- imphnen-hackathon/src/teams/infrastructure/http/routes.rs | 4 ++-- imphnen-hackathon/src/users/infrastructure/http/routes.rs | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/imphnen-hackathon/src/admin/infrastructure/http/routes.rs b/imphnen-hackathon/src/admin/infrastructure/http/routes.rs index 3188c35..811500a 100644 --- a/imphnen-hackathon/src/admin/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/admin/infrastructure/http/routes.rs @@ -33,8 +33,7 @@ pub fn hackathon_admin_routes(pool: Arc) -> Router { ) .route("/admin/winners/{team_id}", delete(admin_remove_winner)) .layer(Extension(service)) - .layer(Extension(pool.clone())) .layer(from_fn(admin_only)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/chat/infrastructure/http/routes.rs b/imphnen-hackathon/src/chat/infrastructure/http/routes.rs index 129e326..d9dca59 100644 --- a/imphnen-hackathon/src/chat/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/chat/infrastructure/http/routes.rs @@ -22,6 +22,6 @@ pub fn build_chat_routes(pool: Arc) -> Router { ) .route("/chat/messages/{message_id}", delete(delete_message_handler)) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/invitations/infrastructure/http/routes.rs b/imphnen-hackathon/src/invitations/infrastructure/http/routes.rs index dc33eca..c379d30 100644 --- a/imphnen-hackathon/src/invitations/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/invitations/infrastructure/http/routes.rs @@ -26,6 +26,6 @@ pub fn build_invitation_routes(pool: Arc) -> Router { post(invite_team_member_handler), ) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/join_requests/infrastructure/http/routes.rs b/imphnen-hackathon/src/join_requests/infrastructure/http/routes.rs index 96f339c..cef7961 100644 --- a/imphnen-hackathon/src/join_requests/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/join_requests/infrastructure/http/routes.rs @@ -30,6 +30,6 @@ pub fn build_join_request_routes(pool: Arc) -> Router { post(respond_to_join_request_handler), ) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/storage/infrastructure/http/routes.rs b/imphnen-hackathon/src/storage/infrastructure/http/routes.rs index 77bab99..04f2b25 100644 --- a/imphnen-hackathon/src/storage/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/storage/infrastructure/http/routes.rs @@ -18,6 +18,6 @@ pub fn hackathon_storage_routes( .route("/upload/team", post(upload_team_handler)) .route("/upload/submission", post(upload_submission_handler)) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/submissions/infrastructure/http/routes.rs b/imphnen-hackathon/src/submissions/infrastructure/http/routes.rs index 9efa95d..be7c3e3 100644 --- a/imphnen-hackathon/src/submissions/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/submissions/infrastructure/http/routes.rs @@ -37,6 +37,6 @@ pub fn hackathon_submissions_routes(pool: Arc) -> Router { post(cancel_submission_handler), ) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) } diff --git a/imphnen-hackathon/src/teams/infrastructure/http/routes.rs b/imphnen-hackathon/src/teams/infrastructure/http/routes.rs index 25275d1..79bd104 100644 --- a/imphnen-hackathon/src/teams/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/teams/infrastructure/http/routes.rs @@ -33,8 +33,8 @@ pub fn build_team_routes(pool: Arc) -> Router { delete(remove_member_handler), ) .layer(Extension(service)) - .layer(Extension(pool.clone())) - .layer(from_fn(hackathon_auth_middleware)); + .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool.clone())); Router::new().merge(public).merge(protected) } diff --git a/imphnen-hackathon/src/users/infrastructure/http/routes.rs b/imphnen-hackathon/src/users/infrastructure/http/routes.rs index fece8a4..06efd63 100644 --- a/imphnen-hackathon/src/users/infrastructure/http/routes.rs +++ b/imphnen-hackathon/src/users/infrastructure/http/routes.rs @@ -19,6 +19,6 @@ pub fn hackathon_users_routes(pool: Arc) -> Router { .route("/users/{user_id}", get(get_user_handler)) .route("/users/{user_id}/teams", get(get_user_teams_handler)) .layer(Extension(service)) - .layer(Extension(pool)) .layer(from_fn(hackathon_auth_middleware)) + .layer(Extension(pool)) }