Skip to content

fix(github): pass workspace id as state to App install url#42

Merged
ABB65 merged 1 commit into
mainfrom
fix/github-app-install-state
May 12, 2026
Merged

fix(github): pass workspace id as state to App install url#42
ABB65 merged 1 commit into
mainfrom
fix/github-app-install-state

Conversation

@ABB65
Copy link
Copy Markdown
Member

@ABB65 ABB65 commented May 12, 2026

Summary

  • getGitHubAppInstallUrl() was returning a bare /installations/new URL with no state parameter, so GitHub's post-install callback (/api/github/setup) always responded 400 github.workspace_state_required. Observed on staging access logs as GET /api/github/setup 400 — the user is stuck on the "install GitHub App" step with no way past.
  • Util now accepts workspaceId and appends it via URLSearchParams. The four callsites (AppSidebar, ConnectRepoDialog, StarterKitDialog, WorkspaceGitHubPanel) pass activeWorkspace.value.id and short-circuit if no active workspace is loaded.

Test plan

  • Local dev: open ConnectRepoDialog without an installation → click Install GitHub App → verify popup URL contains ?state=<workspaceId>
  • Same for AppSidebar empty state, StarterKitDialog install screen, and WorkspaceGitHubPanel install button
  • Complete the GitHub App install flow on staging → confirm callback redirects to /w/<slug> (not 400)
  • Verify workspaces.github_installation_id is populated after the redirect

`server/api/github/setup.get.ts` requires the `state` query parameter
(it carries the workspace ID that the post-install callback writes the
installation_id onto). `getGitHubAppInstallUrl()` was emitting a bare
`/installations/new` URL with no state, so every install attempt from
the sidebar / connect-repo dialog / starter-kit dialog / workspace
GitHub settings panel landed on the callback with `state` missing and
returned 400 — observed on staging access logs as `GET /api/github/setup 400`.

- `app/utils/github-app.ts` now takes `workspaceId` and appends it via
  `URLSearchParams` (handles encoding for any future non-UUID ids).
- The four callsites (`AppSidebar`, `ConnectRepoDialog`, `StarterKitDialog`,
  `WorkspaceGitHubPanel`) each pass `activeWorkspace.value.id` and short-circuit
  if no active workspace is loaded. In practice the install button is only
  rendered when `activeWorkspace` is present, but the guard keeps the type
  contract honest and prevents a runtime crash if state ever drifts.

No backend change — the callback contract was already correct.
@ABB65 ABB65 merged commit 5d9f150 into main May 12, 2026
1 check passed
@ABB65 ABB65 deleted the fix/github-app-install-state branch May 12, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant