fix: pass Authorization header in server-side team API calls #19
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/westside-landing!19
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "18-bug-team-api-calls-return-401-server-sid"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Server-side load functions in
/admin/teamsand/teamswere callingfetchTeams()andfetchTeamOverview()without the Keycloak access token, causing 401 Unauthorized responses from basketball-api. This fix wires the token through fromevent.locals.accessToken, matching the pattern already established in/coach/+page.server.js.Changes
src/lib/server/api.js: Added optionaltokenparameter tofetchTeams(),fetchTeam(), andfetchTeamOverview(). When provided, setsAuthorization: Bearerheader. Backwards compatible.src/routes/admin/teams/+page.server.js: ExtractaccessTokenfromevent.localsin theloadfunction and pass it tofetchTeams()andfetchTeamOverview(). Form actions already had this pattern.src/routes/teams/+page.server.js: Accepteventparameter inload(was previously bareload()), extractaccessToken, and pass to both API calls.Test Plan
/admin/teams-- teams list loads without 401/teams-- teams load with or without active session/coachpage still works (no regression -- already correct)/admin/teams(create team, assign players, etc.) still workReview Checklist
Related
Review: APPROVED
Reviewed the diff (3 files, +42/-11). All changes are correct and scoped to the bug:
api.js:fetchTeams,fetchTeam,fetchTeamOverviewnow accept optionaltokenparam, conditionally setAuthorization: Bearerheader. Backwards compatible./admin/teams/+page.server.js: Extractsevent.locals.accessTokeninload, passes tofetchTeamsandfetchTeamOverview. Matches pattern already used in actions on the same file./teams/+page.server.js: Acceptseventinload(was bare), extracts token, passes through.No secrets, no unrelated changes, no regressions. Pattern matches
/coach/+page.server.jsexactly.PR #19 Frontend Review
DOMAIN REVIEW
Accessibility: No UI changes in this PR -- all modifications are server-side
+page.server.jsand$lib/server/api.js. No a11y impact.Performance: No performance concerns. The
Authorizationheader is conditionally added only when a token exists, avoiding any unnecessary overhead. ThePromise.allparallel fetch pattern is correctly preserved.Responsive / UX: No template or component changes. The fix ensures team data actually loads for authenticated users, which is a UX improvement (previously users saw empty/error states due to 401s).
Design quality: N/A -- no visual changes.
Code quality: The fix is clean, minimal, and well-scoped. The optional
tokenparameter added tofetchTeams(),fetchTeam(), andfetchTeamOverview()inapi.jsmaintains full backwards compatibility. The pattern exactly mirrors the existing approach increateTeam(),updateTeam(),assignPlayers(),unassignPlayer(), and the/coach/+page.server.jsload function. JSDoc annotations are correctly updated with the new parameter.BLOCKERS
None. The fix is correct and addresses the root cause (missing
Authorizationheader on server-side team API load functions).NITS
@ts-ignoreforevent.locals.accessToken-- This pattern appears 25 times across the codebase. A properApp.Localsinterface declaration insrc/app.d.tswould eliminate all of these suppressions. Not introduced by this PR, but worth tracking as a follow-up issue./teamsroute has no auth guard -- The/teams/+page.server.jsload function now passes the access token but does not check for a session or enforce any role. If the basketball-api/api/teamsendpoint requires authentication, unauthenticated visitors will hit the catch block and see empty data withapiConnected: false. This is pre-existing behavior (not a regression from this PR), but worth noting: if the intent is that/teamsis a public route, the token pass-through is harmless; if it requires auth, a redirect guard should be added. Consider opening a follow-up issue.Header object style inconsistency -- The PR uses
headers['Authorization'] = ...(bracket notation) while the existing mutating functions (createTeam,updateTeam, etc.) useAuthorization: ...(object literal shorthand). Minor inconsistency, not blocking.SOP COMPLIANCE
18-bug-team-api-calls-return-401-server-sidreferences issue #18)Closes #18present in Related sectionplan-2026-03-08-tryout-prepis not mentioned in the PR bodyfix: pass Authorization header in server-side team API calls)PROCESS OBSERVATIONS
plan-2026-03-08-tryout-prepfor traceability. This is a minor SOP gap.api.jsfunctions. This is a pre-existing gap -- the entire$lib/server/api.jsmodule has no test coverage. Not blocking for a 3-file bug fix, but the pattern of shipping server-side API wrappers without tests increases change failure risk over time.@ts-ignoreproliferation: 25 occurrences across 10 files. A singleApp.Localstype declaration would eliminate these. Candidate for a follow-up issue or convention.VERDICT: APPROVED
The fix is correct, minimal, backwards-compatible, and follows the established codebase pattern. It resolves the 401 bug for
/admin/teamsand/teamsroutes. The two SOP gaps (missing Design Decisions section and missing plan slug reference) are non-blocking for a bug fix PR. The nits are pre-existing patterns, not regressions.