Skip to content

[Fix] Link GitHub account 404s when app credentials are stored in deployment env vars - #148

Merged
mrubens merged 1 commit into
developfrom
fix/github-link-account-client-id
Jul 10, 2026
Merged

[Fix] Link GitHub account 404s when app credentials are stored in deployment env vars#148
mrubens merged 1 commit into
developfrom
fix/github-link-account-client-id

Conversation

@mrubens

@mrubens mrubens commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Clicking Link GitHub (Settings → Linked accounts, onboarding, home onboarding card) redirected to github.com/login/oauth/authorize?client_id=&..., which GitHub 404s.

startAuthenticateGitHubAccountCommand built the authorize URL from Env.GITHUB_CLIENT_ID, which only reads process env and defaults to an empty string. Deployments that created their GitHub App through the in-product manifest flow store credentials encrypted in the environment_variables table, so the client id was empty at URL-build time.

getGitHubOAuthUser (the callback's code→token exchange, shared with OAuth-on-install linking) read both GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET the same way, so the callback would have failed even with a correct URL.

Fix

  • Resolve the client id via resolveDeploymentEnvVar (process env first, then DB-stored deployment credentials), matching the rest of the GitHub commands.
  • When no client id is configured, return a clear error ("Configure a GitHub App for this deployment before linking your GitHub account...") instead of emitting a broken URL. The settings UI already toasts result.error.
  • Same treatment for the client id + secret in getGitHubOAuthUser.

Testing

  • New unit tests: authorize URL built from the deployment-resolved client id; unconfigured deployments get the error result instead of a URL.
  • All 11 tests in mutations.test.ts pass; typecheck, Prettier, ESLint clean.
  • Verified at runtime against a dev deployment configured via the manifest flow (no GITHUB_CLIENT_ID in process env): the credentials now resolve from the DB and the link flow reaches GitHub's authorize page.

…linking accounts

The Link GitHub account button built the authorize URL from
Env.GITHUB_CLIENT_ID, which only reads process env and defaults to an
empty string. Deployments that created their GitHub App through the
in-product manifest flow store credentials encrypted in the
environment_variables table, so the button produced
client_id= and GitHub returned a 404.

Resolve the client id via resolveDeploymentEnvVar like the rest of the
GitHub commands, and return a clear configuration error instead of a
broken URL when no client id is available. Apply the same fix to the
OAuth code-to-token exchange, which read both the client id and secret
from process env and would have failed the callback for the same
deployments.
@roomote-roomote

roomote-roomote Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

Reviewed the credential-resolution fix in apps/web/src/trpc/commands/github/mutations.ts and its tests. resolveDeploymentEnvVar returns a trimmed non-empty string or null, so the !clientId/!clientSecret guards are correct, both the authorize-URL builder and the shared code-to-token exchange are fixed, and all three UI entry points (onboarding step, home onboarding card, linked-accounts settings) already surface the new success: false error via toast.

@mrubens
mrubens merged commit b0b949e into develop Jul 10, 2026
1 check passed
mrubens pushed a commit that referenced this pull request Jul 11, 2026
…S templates

- Update the deployment-resolved GitHub client id test to mock
  R_GITHUB_CLIENT_ID (stale resolution from the develop merge of #148)
- Rename legacy names in .env.local.example / .env.production.example to
  the canonical R_* set and drop dead ROOMOTE_AUTH_TELEGRAM_* entries
- Point .roomote/environments/roomote.yaml at R_APP_ENV / R_APP_URL /
  R_PUBLIC_URL so repo agent environments configure the renamed runtime
- Fix missed APP_ENV -> R_APP_ENV in fly.toml, render.yaml, the Railway
  template/README, deploy/README.md, and the installer (the N-1 dual-write
  shim in the prod compose and upgrade-compatibility lane is untouched)
@mrubens
mrubens deleted the fix/github-link-account-client-id branch July 12, 2026 04:19
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.

2 participants