Skip to content

feat(auth): persist org_name and org_id from login/signup#199

Merged
AlephNotation merged 1 commit into
mainfrom
fix/persist-org-name
May 12, 2026
Merged

feat(auth): persist org_name and org_id from login/signup#199
AlephNotation merged 1 commit into
mainfrom
fix/persist-org-name

Conversation

@AlephNotation
Copy link
Copy Markdown
Contributor

@AlephNotation AlephNotation commented May 12, 2026

Why

When a user runs vers login or vers signup, the API response includes both org_name and org_id. The CLI prints them in the success banner and then discards them. That makes the canonical <org>/<repo>:<tag> reference unconstructable client-side, even though the server already told us the org name.

Surfaced naturally while documenting how to share a public repo: vers repo get pi-agent doesn't say what org pi-agent belongs to, because the API's RepositoryInfo response doesn't include it (PublicRepositoryInfo does, but that's a different endpoint). Without persisted org info, a user can't construct their own public reference without the upstream API including it on every endpoint.

What

  1. Config struct gains OrgName and OrgID fields (omitempty so existing ~/.versrc files don't gain noisy keys).
  2. New SaveAuth(apiKey, orgName, orgID) helper — single write, used by login. Empty values don't clobber persisted ones, so a future key-only rotation preserves org identity.
  3. New GetOrgName() helper — mirrors GetAPIKey: VERS_ORG env wins, falls back to config.
  4. Login + signup paths updated to persist org info on success.

Doesn't include (deliberate follow-ups, not yet tracked)

  • Surfacing org_name in vers agent-context — a natural addition; this PR unblocks it but doesn't ship it
  • vers repo get synthesizing <org>/<repo>:<tag> client-side
  • vers whoami to introspect the persisted identity

A follow-up issue should be filed for these. Issue #193 currently only covers the feedback and jobs blocks of agent-context; org/identity surfacing is a separate concern.

Tests

New TestGetOrgName with 4 sub-cases:

--- PASS: TestGetOrgName (0.00s)

Covers: no config returns empty, persist-and-read, VERS_ORG env override, empty values to SaveAuth don't clobber existing.

All existing tests pass. make build, gofmt, go vet clean.

Backwards compatibility

Strictly additive. Existing ~/.versrc files without orgName/orgID continue to work; the fields populate on next login/signup. No breaking change.

The login/signup API response includes both org_name and org_id. Prior to
this change the CLI printed them in the success banner and discarded them.

Now they're persisted to ~/.versrc as orgName and orgID, with a GetOrgName()
helper that mirrors GetAPIKey's env-then-config precedence (VERS_ORG wins).
A new SaveAuth(apiKey, orgName, orgID) helper performs a single write so the
login path doesn't need to load+modify+save.

Unblocks two follow-ups:
- vers agent-context can surface the current org without an extra API call
- vers repo get can synthesize <org>/<repo>:<tag> client-side, so users can
  see the canonical public reference for their own repos without consulting
  the public discovery endpoint

Empty values passed to SaveAuth don't clobber persisted ones, so a key
rotation via SaveAuth(newKey, "", "") preserves the previously-stored
org identity.

Tested:
- internal/auth/auth_test.go gains TestGetOrgName with four sub-cases (no
  config, persist-and-read, env override, empty-doesn't-clobber)
- all existing tests pass
@AlephNotation AlephNotation merged commit dbdfff8 into main May 12, 2026
6 checks passed
@AlephNotation AlephNotation deleted the fix/persist-org-name branch May 12, 2026 04:08
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