Skip to content

feat: move sign-in to @convex-dev/auth 2.0 - #47

Merged
hyochan merged 2 commits into
mainfrom
feat/convex-auth-2
Nov 20, 2026
Merged

hyochan merged 2 commits into
mainfrom
feat/convex-auth-2

Conversation

@hyochan

@hyochan hyochan commented Nov 20, 2026

Copy link
Copy Markdown
Member

Summary

Moves sign-in from @convex-dev/auth 0.0.98 to 2.0.0 (replaces Dependabot's #44, which only bumped the version). In 2.0 auth is a set of Convex components: the core auth component holds sessions and refresh tokens and the deployment signs the tokens; authGithub holds GitHub accounts and serves the OAuth callback at <CONVEX_SITE_URL>/oauth/github/callback.

Do not merge until the cutover below is scheduled. Merging deploys, which signs every client out.

Changes

Backend

  • convex/convex.config.ts mounts auth and authGithub (GitHub client id/secret bound from the app env); convex/auth.config.ts uses convexAuthProvider().
  • convex/auth.ts: setupConvexAuth with one-hour access tokens (as before, so GITDOG_TOKEN automation keeps working) and setupGithub with redirects allowed only to SITE_URL and the CLI's five fixed loopback ports.
  • users is now an app-defined table with githubAccountId. createUserFromGithub returns the user who already has that GitHub id, and while the 0.0.x tables exist it also links a user from authAccounts, so a sign-in between deploy and migration never creates a second, empty account. updateUserFromGithub refreshes the profile and refuses a changed GitHub id.
  • convex/users/githubAccount.ts replaces every direct authAccounts read (installation attestation freshness, invitations, webhook actor and legal lookups).
  • users/migrations:migrateToAuthV2: copies each GitHub account onto its user, then deletes all 0.0.x auth rows; batched and idempotent, and it stops without deleting if a GitHub id is claimed twice.
  • convex/_utils/auth.ts wraps 2.0's getAuthUserId so actions typecheck.
  • The /.well-known/openid-configuration and /.well-known/jwks.json paths 0.0.x served stay, now backed by the workload keys Anthropic federation verifies (same key as /ai/workload/jwks.json). JWT_PRIVATE_KEY/JWKS stay for federation only.

Web: ConvexAuthProvider gets api.auth; the consent page signs in with useSignInWithGithub and an absolute same-origin redirectTo.

CLI 0.5.0: startSignInWithGithub / completeSignInWithGithub, refreshSession, signOut (by refresh token, no refresh first); the login listener tries ports 41721–41725 (the server allows exactly these) and only follows GitHub's authorize page. Installed CLIs need login again after cutover.

Tests: test/helpers/auth.ts signs test users in through a real 2.0 session (166 call sites converted); new tests for the user callbacks, the migration and a sign-in that lands before it. bun run test:dev mints sessions through the core component.

Rehearsed on dev

Deployed to fortunate-chihuahua-679, ran migrateToAuthV2 (linked GitHub 27461460 to its user, deleted 12 old rows), signed in for real with the new CLI ("Signed in as hyochan"): the GitHub component linked the account to the existing user (user count unchanged at 22), an authenticated call worked, and logout revoked the session. The discovery routes serve the keyed workload JWKS.

Cutover checklist (production)

  1. Add https://calm-hippopotamus-56.convex.site/oauth/github/callback to the gitdogai GitHub App redirect URIs (keep the existing ones).
  2. Merge; the deploy workflow publishes Convex and the web app.
  3. Run bunx convex run --prod users/migrations:migrateToAuthV2 until done is true.
  4. Sign in on gitdog.dev and with the CLI; check a review and an Anthropic call.
  5. Publish the CLI 0.5.0 release.
  6. Follow-up: drop legacyAuthTables and users/migrations.ts, remove /api/auth/callback/github from the GitHub Apps, close chore(deps): bump @convex-dev/auth from 0.0.98 to 2.0.0 #44.

Checks

bun run lint, bun run typecheck, prettier --check ., bun run build, bun run test (2105 passed), bun run check:api, bun run test:cli (116 passed). An independent security review found no account-takeover or open-redirect paths; its findings (pre-migration sign-in duplicating a user, federation discovery paths, CLI version, test:dev, docs) are fixed.

🤖 Generated with Claude Code

Sign-in now runs on @convex-dev/auth 2.0 components: sessions and refresh
tokens in the core component, GitHub accounts in authGithub, tokens signed
by the deployment.

- Gitdog keeps the GitHub account id on its own users table; every lookup
  that read authAccounts now reads users.githubAccountId.
- createUserFromGithub returns the existing user for a known GitHub id, and
  until migrateToAuthV2 has run it also links users from the 0.0.x
  authAccounts table, so nobody gets a second, empty account.
- users/migrations:migrateToAuthV2 copies each GitHub account onto its user
  and deletes the 0.0.x auth rows; the legacy tables stay defined until it
  has run in production.
- One-hour access tokens, as before, so GITDOG_TOKEN automation still works.
- The OpenID discovery and JWKS paths 0.0.x served stay, backed by the
  workload keys Anthropic federation verifies.
- Web: the consent page signs in with useSignInWithGithub.
- CLI 0.5.0: start/complete sign-in, refreshSession and signOut; the login
  listener uses one of five fixed loopback ports the server allows.
- Tests sign in through real 2.0 sessions (test/helpers/auth.ts); new tests
  cover the user callbacks and the migration, including a sign-in before it.
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit b99cd6c):

https://codeyou-df251--pr47-feat-convex-auth-2-mjqosgaj.web.app

(expires Fri, 27 Nov 2026 13:32:03 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 844dad9c62537d028cabc21008e4e2e4031ce4e5

@gitdogai gitdogai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 potential issue in 6d0d4b9

13 of 104 changed files were not fully reviewed.

Not a merge approval. Tests were not run. Gitdog

Comment thread convex/auth.ts Resolved
@hyochan
hyochan merged commit a6ac96c into main Nov 20, 2026
9 checks passed
@hyochan
hyochan deleted the feat/convex-auth-2 branch November 20, 2026 14:12
hyochan added a commit that referenced this pull request Nov 20, 2026
Follow-up to #47. Production ran `users/migrations:migrateToAuthV2` on
2026-11-20: both users have `githubAccountId` and all six 0.0.x auth
tables are empty (checked again before this PR).

- Drop `legacyAuthTables` from the schema (verified on the dev
deployment: Convex removes the empty tables' indexes).
- Delete `convex/users/migrations.ts` and the `authAccounts` fallback in
`createUserFromGithub`; the remaining callback tests move to
`test/convex/users/githubSignIn.test.ts`.
- `test:dev` no longer lists the old tables in its cleanup.

Checks: lint, typecheck, prettier, build, `bun run test` (2102 passed),
`check:api`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
hyochan added a commit that referenced this pull request Nov 20, 2026
## Summary

Follow-ups found reviewing today's auth 2.0 work (#46, #47, #48) and
own-key cost UI (#45).

- **Connect page**: after 2.0, installation recovery reports
`reauth_required` whenever no fresh attestation exists, so a brand-new
user saw "Finishing GitHub connection" instead of Install. Users without
an installation now see Install, with "Already installed? Verify GitHub
access" as a secondary action. The verification screen is shown only
while an installation callback is pending. Screen choice moved into
`resolveConnectScreen` with a table test.
- **Usage**: the own-key section said reviews run on Gitdog tokens
whenever no key worked, but saved keys never fall back. It now
distinguishes no key / no working key / temporary outage. The page waits
for own-key cost before rendering.
- **Consent page**: shows why a GitHub sign-in failed
(`useOauth().flowError`).
- **CLI**: `github verify` reuses `validateAuthRedirect` (also handles a
missing URL); install hints mention `github verify` before `github
recover`.
- **Smaller**: `getTicketUsage` and recent own-key runs respect
`githubLifecycleOnly`; long-context price note in the model picker;
per-provider "this period" wording; shared `actionTypeLabel`;
screen-reader request count on the usage chip; unused
`repositories[].actions` removed.
- **Docs**: `getAuthUserId` import path, CLI fixed ports, verify-access
architecture line, `CUSTOM_AUTH_SITE_URL` comment.
- **Tests**: session auth rejects a bare user-id subject and a revoked
session; sign-in redirect allow/deny at the mutation; CLI port fallback
and all-ports-busy; consent flow errors. `CONVEX_CLOUD_URL` moved to
test setup.

## Verification

`bun run lint`, `typecheck`, `build`, `format:check`, `check:api`,
`typecheck:cli`, `test:cli` (118 pass), `vitest run` (2124 pass).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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