Skip to content

/api/repos fetched without the active-team header shows personal repos inside a team scope #412

Description

@charlesrhoward

Problem

Inside a team scope, the status bar, the assignments page and the triggers pane show the user's personal repos instead of the team's. Six components fetch /api/repos under six different SWR keys, and four of them never attach the x-mogplex-team-id header. The same page load also fires two to four duplicate uncached requests.

Where

Correct (sends the header):

  • hooks/use-repos.ts:10-24 (key ["/api/repos", activeTeamId], uses getActiveTeamRequestHeaders)

Wrong (no header):

  • components/status-bar.tsx:26 and :44
  • hooks/use-assignments.ts:19
  • components/panes/inline-trigger-form.tsx:30
  • components/panes/triggers-pane.tsx:33-36

Root cause: lib/client-fetch.ts:34 (fetchJsonArray) calls bare fetch with whatever init it is given, and these callers pass none. There is no global SWRConfig provider, so nothing dedupes across keys.

Fix

  1. Replace every direct /api/repos fetch in the four wrong files with useRepos() from hooks/use-repos.ts. Delete the local fetchers.
  2. Grep for any other "/api/repos" string in components/ and hooks/ and do the same (rg -n '"/api/repos' components hooks).
  3. Do not add a second hook. One key, one fetcher.

Exit criteria

  • rg -n '"/api/repos' components hooks app returns only hooks/use-repos.ts and any server-side callers.
  • Unit test in tests/unit/ for useAssignments (or the status bar) asserts the request includes the x-mogplex-team-id header when a team is active. Must fail on main.
  • Manual on preview: switch to a team scope, confirm the status bar repo count matches the team's Projects page, and confirm in the Network tab that /api/repos is requested once per page load.
  • pnpm lint, pnpm typecheck, pnpm test:unit pass.

Out of scope

Adding a global SWRConfig or a general team-aware fetch wrapper. Worth doing, but as its own change.

https://claude.ai/code/session_01SQ4nS96XYRztd5w9QkubPf

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Correctness or safety. Fix before anything else.apiAPI routes and request handling.bugSomething isn't workingux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions