fix: correct middleware layer ordering in hackathon routes

The hackathon_auth_middleware requires Arc<PgPool> 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) <noreply@anthropic.com>
This commit is contained in:
maulanasdqn
2026-04-09 22:21:30 +07:00
co-authored by Claude Opus 4.6
parent 4ee00f1fe5
commit f225ee8969
8 changed files with 9 additions and 10 deletions
@@ -33,8 +33,7 @@ pub fn hackathon_admin_routes(pool: Arc<PgPool>) -> 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))
}
@@ -22,6 +22,6 @@ pub fn build_chat_routes(pool: Arc<PgPool>) -> 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))
}
@@ -26,6 +26,6 @@ pub fn build_invitation_routes(pool: Arc<PgPool>) -> Router {
post(invite_team_member_handler),
)
.layer(Extension(service))
.layer(Extension(pool))
.layer(from_fn(hackathon_auth_middleware))
.layer(Extension(pool))
}
@@ -30,6 +30,6 @@ pub fn build_join_request_routes(pool: Arc<PgPool>) -> Router {
post(respond_to_join_request_handler),
)
.layer(Extension(service))
.layer(Extension(pool))
.layer(from_fn(hackathon_auth_middleware))
.layer(Extension(pool))
}
@@ -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))
}
@@ -37,6 +37,6 @@ pub fn hackathon_submissions_routes(pool: Arc<PgPool>) -> Router {
post(cancel_submission_handler),
)
.layer(Extension(service))
.layer(Extension(pool))
.layer(from_fn(hackathon_auth_middleware))
.layer(Extension(pool))
}
@@ -33,8 +33,8 @@ pub fn build_team_routes(pool: Arc<PgPool>) -> 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)
}
@@ -19,6 +19,6 @@ pub fn hackathon_users_routes(pool: Arc<PgPool>) -> 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))
}