From 9dd5da514cd93019e909af29112521caba0a6cc2 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 8 May 2026 08:44:50 -0400 Subject: [PATCH] refactor(server/api): migrate me/* + events preludes (A2 5/N) --- internal/api/events.go | 4 +--- internal/api/me_history.go | 4 +--- internal/api/me_password.go | 4 +--- internal/api/me_profile.go | 4 +--- internal/api/me_system_playlists.go | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/internal/api/events.go b/internal/api/events.go index 79a1d3ca..2e95ee36 100644 --- a/internal/api/events.go +++ b/internal/api/events.go @@ -9,7 +9,6 @@ import ( "github.com/jackc/pgx/v5" "git.fabledsword.com/bvandeusen/minstrel/internal/apierror" - "git.fabledsword.com/bvandeusen/minstrel/internal/auth" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" ) @@ -33,9 +32,8 @@ type okResponse struct { } func (h *handlers) handleEvents(w http.ResponseWriter, r *http.Request) { - user, ok := auth.UserFromContext(r.Context()) + user, ok := requireUser(w, r) if !ok { - writeErr(w, apierror.ErrUnauthorized) return } var req eventRequest diff --git a/internal/api/me_history.go b/internal/api/me_history.go index 845d9d40..0520a386 100644 --- a/internal/api/me_history.go +++ b/internal/api/me_history.go @@ -5,7 +5,6 @@ import ( "net/http" "git.fabledsword.com/bvandeusen/minstrel/internal/apierror" - "git.fabledsword.com/bvandeusen/minstrel/internal/auth" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" ) @@ -15,9 +14,8 @@ import ( // offset/limit; has_more = (len(rows) == limit) is a cheap heuristic // that errs on the "true" side at the exact-end boundary. func (h *handlers) handleGetMyHistory(w http.ResponseWriter, r *http.Request) { - user, ok := auth.UserFromContext(r.Context()) + user, ok := requireUser(w, r) if !ok { - writeErr(w, apierror.ErrUnauthorized) return } diff --git a/internal/api/me_password.go b/internal/api/me_password.go index c34993a4..97ee42d7 100644 --- a/internal/api/me_password.go +++ b/internal/api/me_password.go @@ -8,7 +8,6 @@ import ( "git.fabledsword.com/bvandeusen/minstrel/internal/apierror" "git.fabledsword.com/bvandeusen/minstrel/internal/audit" - "git.fabledsword.com/bvandeusen/minstrel/internal/auth" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" ) @@ -21,9 +20,8 @@ type changePasswordReq struct { // the caller proves they know their current password before they can // set a new one. Distinct from the admin-driven reset path. func (h *handlers) handleChangePassword(w http.ResponseWriter, r *http.Request) { - user, ok := auth.UserFromContext(r.Context()) + user, ok := requireUser(w, r) if !ok { - writeErr(w, apierror.Unauthorized("auth_required", "")) return } var req changePasswordReq diff --git a/internal/api/me_profile.go b/internal/api/me_profile.go index 6776183a..349fa165 100644 --- a/internal/api/me_profile.go +++ b/internal/api/me_profile.go @@ -11,7 +11,6 @@ import ( "github.com/jackc/pgx/v5/pgconn" "git.fabledsword.com/bvandeusen/minstrel/internal/apierror" - "git.fabledsword.com/bvandeusen/minstrel/internal/auth" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" ) @@ -39,9 +38,8 @@ type meProfileResp struct { } func (h *handlers) handleUpdateMyProfile(w http.ResponseWriter, r *http.Request) { - user, ok := auth.UserFromContext(r.Context()) + user, ok := requireUser(w, r) if !ok { - writeErr(w, apierror.Unauthorized("auth_required", "")) return } var req updateProfileReq diff --git a/internal/api/me_system_playlists.go b/internal/api/me_system_playlists.go index cae4e131..91903927 100644 --- a/internal/api/me_system_playlists.go +++ b/internal/api/me_system_playlists.go @@ -7,7 +7,6 @@ import ( "github.com/jackc/pgx/v5" "git.fabledsword.com/bvandeusen/minstrel/internal/apierror" - "git.fabledsword.com/bvandeusen/minstrel/internal/auth" "git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" ) @@ -24,9 +23,8 @@ type systemPlaylistsStatusResp struct { // Returns the caller's system_playlist_runs row, or zero-values when no row // exists yet (i.e. the user has never had a build attempted). func (h *handlers) handleGetSystemPlaylistsStatus(w http.ResponseWriter, r *http.Request) { - caller, ok := auth.UserFromContext(r.Context()) + caller, ok := requireUser(w, r) if !ok { - writeErr(w, apierror.Unauthorized("unauthenticated", "no session")) return }