Repository navigation
feat(cli): Pick the stored account from the target org or server - #1528
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 16, 2026 21:06
b9d3f2c to
a9699d8
Compare
BYK
reviewed
Oct 16, 2026
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 16, 2026 23:21
ad24de9 to
2139d1a
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:21
0e933d8 to
46c6dc7
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:30
46c6dc7 to
c288b7b
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:37
c288b7b to
66b331e
Compare
BYK
marked this pull request as ready for review
October 17, 2026 01:09
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:11
66b331e to
dc83d07
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:16
dc83d07 to
3de3978
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:46
2715364 to
6c99389
Compare
BYK
approved these changes
Oct 17, 2026
BYK
approved these changes
Oct 17, 2026
…sts unsnapshotted Replacing credentials in place (`sentry auth login --force`, automatic re-login) wrote to the account selected for the configured server, so SENTRY_HOST/SENTRY_URL or `.sentryclirc` naming another stored account's server overwrote that account instead of the active one. The legacy NULL host backfill had the same mix-up. Both now use the stored active account. Pasting a SaaS URL read the active token host after clearing the URL; with an env token in effect that snapshotted the token's host as SaaS even when it was scoped to a self-hosted server. Compare the stored account in effect instead, which never touches the env-token snapshot.
Member
|
I wonder if we should modify commands like "org list" to list all available organizations under all accounts. Wdyt? |
`sentry auth login --force` (and automatic re-login) replaced the stored active account even when the login targeted another server, so a self-hosted login could overwrite a SaaS account and vice versa. Accounts are now always tied to their server: an in-place login replaces the active account only when it is on the login's server, otherwise the most recently used account on that server, and adds a new account when that server has none. Accounts on other servers are never touched. The `--force --token` path removes only that server's previous login, after the new token validates. Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
BYK
requested changes
Oct 19, 2026
BYK
left a comment
Member
There was a problem hiding this comment.
Looks like we can DRY this code up a bit. Also there are 2 important warden warnings we should address.
- Bake the org-list TTL into `hasCachedOrgList` (BYK review). - DRY up server matching in db/auth: `getExplicitServerUrl()` and `findUsableAccountOnServer()` replace repeated inline logic, and every same-server check goes through `isAccountOnServer`. - A pasted SaaS URL now always pins SENTRY_URL to SaaS when a SaaS account is stored, so org-based selection can't switch to a self-hosted account sharing the org slug or id (Warden). - The command auth guard defers to target-based selection when the account in effect is logged out but another stored account can authenticate; requests still fail with AuthError when none is picked (Warden).
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3600df9. Configure here.
The pin only applied when a usable SaaS account existed. With the SaaS login logged out (now allowed past the auth guard) or no SaaS account at all, org-based selection could still switch a pasted sentry.io URL to a self-hosted account that shares the org slug. Pin SENTRY_URL to SaaS whenever any account is stored, so only SaaS accounts are candidates and an unusable one fails to authenticate instead.
Pinning SENTRY_URL to SaaS whenever any account was stored broke the single-account case: a lone login on another server (the e2e mock server) pasting a sentry.io URL got a host-scope error instead of its own server answering, as before multi-account. Pin only when a SaaS account is stored (logged in or not) or accounts span several logins — the cases where org-based selection could route the URL elsewhere.
…s SaaS Pinning SENTRY_URL to SaaS for a pasted sentry.io URL left the persisted default marker in place when defaults.url was already SaaS, so the pin still read as the yielding default and org selection could switch to a self-hosted account. Clear the marker when pinning. Co-Authored-By: byk <burak.kaya@sentry.io>
…g's account - assertRcUrlTrusted accepts a non-SaaS .sentryclirc URL when a usable stored account is on it, like a pasted URL, so a logged-out active account no longer blocks org-based selection of a peer on that server. - 401/403 scope recovery (and ensureScopesForAction) re-authorizes the account the invocation picked for its target org instead of replacing the active account, so the retry uses the new grant. The login must be approved as that account's user; otherwise nothing is stored.
DSN resolution can yield an org id without its `o` prefix. Sentry org slugs are never entirely numeric, so pass such ids to selectAccountForOrg as the org id too; otherwise the account that has the org cached by id was never selected.
The no-cached-org-list deference in selectAccountForOrg exists to respect the user's active account after `auth switch`. An account chosen only because it is the most recently used one on the configured server now yields to a stored account on that server that knows the org. Co-Authored-By: byk <burak.kaya@sentry.io>
BYK
approved these changes
Oct 19, 2026
This branch was previously deployed
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.

Stacked on #1526. Covers the automatic-selection half of #1396: with several stored accounts, commands use the account that fits what they target, so users don't have to
sentry auth switchback and forth.How the account is chosen (per invocation, most specific first)
resolveOrgRegion/resolveEffectiveOrg, so it covers the ~55 org-scoped call sites and DSNoNNNNids.SENTRY_HOST/SENTRY_URL,.sentryclirc, or a pasted Sentry URL for another account's server selects the stored account on that server. Previously this was aHostScopeError.Guardrails
token-host.ts.auth switch), it is kept. An account that simply hasn't used the org yet can't be overridden by one that has.defaults.urlcounts as soft: when the pinned account is elsewhere, it yields to that account's host.SENTRY_FORCE_ENV_TOKENis never overridden.Storage
Schema v19 adds
org_regions.account_id. Writes record the account whose credentials fetched the row, following in-process refresh-token rotation. The migration backfills existing rows by matching credential identity. The org→account mapping is warm right away for new logins, because login already warms the org cache.Memoized credential state (token, fingerprint, row, stored-creds flag) is now keyed by selection, and user info reads and writes go to the account in effect. Account management (
switch,logout,list) still works on the stored active account.Not covered
via byk.
--
View Junior Session [Sentry]