Repository navigation
Conversation
Keep several Convex accounts logged in on one machine and bind project directories to them, so projects owned by different accounts can be worked on side by side (convex#326). - `~/.convex/config.json` gains `accounts` keyed by Convex member id, `instances` binding directories to accounts, and `settings`. The top-level `accessToken` mirrors the default account so older CLI versions keep working. Nothing changes until `npx convex login --account` adds a second account. - New `npx convex account` command: list (with live token checks), use, unbind, default, describe, settings. `login --account [member-id]`, `login --yes`, `logout --account` and `logout --all` are new options. - `npx convex login` checks the account token instead of a deploy key, which stops it logging in again on every run when CONVEX_DEPLOY_KEY is set. - A deploy key that overrides the login is called out in a banner on login/status/list and in a one-line warning on other commands, only when the machine also has a login. - `npx convex dev` explains when the project in .env.local belongs to another account and offers to switch to or log in to that account before rewriting CONVEX_DEPLOYMENT. - Tokens saved before member ids are identified by comparing personal access token lists, and replaced tokens are revoked unless `revoke-replaced-tokens` is turned off. - Binding a directory checks that the account can reach its CONVEX_DEPLOYMENT. See src/cli/README.md for the full behavior. Tests run the built CLI against a fake Convex API; the single-account tests also pass against convex@1.46.0.
Member
|
Very nice! I had started another implementation that uses named profiles (like "work" / "personal") but I really like the framing here, so I'm going to incorporate the two together and list you as a co-author. I'm thinking of putting the commands under |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #326.
Problem
The CLI keeps one Convex login per machine in
~/.convex/config.json. Anyone whose projects belong to different Convex accounts (consultants, agencies, work and personal) has tologoutandloginwhenever they switch projects, and can't runnpx convex devfor two such projects at the same time.The common workaround, putting
CONVEX_DEPLOY_KEYin each project's.env.local, has sharp edges of its own:npx convex logintests the deploy key instead of the account token, fails, and runs a new browser login on every call. Each run leaves another personal access token on the account.prod:key in.env.localmakesnpx convex dev --onceandnpx convex runact on production, with nothing in the output saying so.devanddeployin the same project need different keys.What this adds
npx convex login --accountadds an account without logging out of the others. Accounts are keyed by Convex member id, since an email can belong to more than one member.npx convex account use <member-id>binds a directory (and everything under it) to an account. Unbound directories use the default account.npx convex account:list(with a live check of every token),use,unbind,default,describe,settings.npx convex devknows when a project belongs to another account. Instead of going straight to "create a new project", it explains which project.env.localpoints to and offers a saved account that can reach it, a login to another account, or setting up a different project. Only the last one rewritesCONVEX_DEPLOYMENT.CONVEX_DEPLOYMENT.npx convex account settings revoke-replaced-tokens false.Existing behavior
Nothing changes for a machine with one login until
npx convex login --accountadds a second account: same config shape, sameloginandlogout, same credentials for every command, nothing revoked. Deploy keys keep priority over accounts, so CI and existing projects behave as before.The top-level
accessTokenkeeps mirroring the default account, so a project pinned to an older CLI keeps working as that account. An olderlogoutstill deletes the whole file.A few changes apply to everyone:
npx convex loginchecks the account token, not the deploy key, so it no longer logs in on every run whenCONVEX_DEPLOY_KEYis set.login,login statusandaccount listshow a banner, and other commands print a one-lineWARNING:. Machines with only a deploy key (CI) see nothing new.npx convex devexplains an inaccessible project as described above. With--teamand--projectit keeps the old flow.npm-packages/convex/src/cli/README.mddocuments every behavior, prompt and non-interactive path.API notes for reviewers
GET /api/dashboard/profile, called with the browser-login token right after the device flow. That endpoint doesn't accept personal access tokens, which is why older tokens are matched throughGET /v1/list_personal_access_tokens. A public "current member" endpoint for personal access tokens would simplify this.GET /v1/deployments/<name>(access check),POST /v1/delete_personal_access_token(revocation),GET /api/teams(default description).Tests
src/cli/accounts.test.ts(47 tests) runs the built CLI against a fake Convex API on localhost, with a fresh home and project directory per test. It covers single-account behavior, deploy keys,login --account, old tokens, revocation, binding and access checks,account list,logout, anddevwith a project another account owns.src/cli/lib/utils/globalConfig.test.ts(16 tests) covers the config helpers.convex@1.46.0(setCONVEX_CLI_UNDER_TESTto itsbin/main.js). The login-loop test fails on 1.46.0 and passes here.npm test,npm run typecheckandeslint src/clipass.