Skip to content

fix(auth): use the configured workspace token in the API client - #61

Merged
timimsms merged 1 commit into
mainfrom
fix/named-workspace-token
Nov 18, 2026
Merged

timimsms merged 1 commit into
mainfrom
fix/named-workspace-token

Conversation

@timimsms

Copy link
Copy Markdown
Owner

Summary

Manager.GetCurrentToken() always read the default keyring account, ignoring config default_workspace, while cu auth status honoured it. After cu auth login -w <name> every API command reported not-authenticated even though auth status said authenticated.

  • New auth.CurrentWorkspace() resolves config default_workspace (so CU_DEFAULT_WORKSPACE also works via viper's env binding), falling back to auth.DefaultWorkspace.
  • GetCurrentToken() (used by api.NewClient and cu api), cu auth status and cu auth logout (when -w is omitted) all resolve through it, so they can't disagree.
  • cu auth login -w <name> now records default_workspace on the --token path too. Before this, only the interactive path did, so login -w prod -t ... would still have been broken even with the client fix. Logging in to the default workspace after a named one switches back to it. A plain cu auth login with no prior named workspace still writes no config file.
  • auth login help text now explains what --workspace does; docs/site/commands/cu_auth_login.md regenerated (only the meaningful hunk is committed).
  • There is no global --workspace flag. The only -w flags are on auth login/auth logout, and both are honoured as described above.

Tests use go-keyring's in-memory keyring.MockInit() and a temp config dir. Nothing touches the real keychain or ~/.config/cu:

  • internal/auth/auth_test.go: named workspace token is resolved; unset config falls back to the default account; env override.
  • internal/cmd/auth_workspace_test.go: auth login -w prod -t … runs end to end, then api.NewClient() succeeds, auth status -o json reports prod, and auth logout removes that token. Also covers a plain login writing no config, and a default login after a named one switching back.

Closes #23

Checklist

  • ./scripts/ci.sh passes locally (or go test -race ./... at minimum)
  • Commit messages use conventional prefixes (feat:, fix:, docs:, chore:, ci:, test:)
  • CLI docs regenerated if command help text changed (cu docs markdown --dir docs/site/commands)
  • Docs updated if user-facing behavior changed

🤖 Generated with Claude Code

GetCurrentToken always read the "default" keyring account, so after
`cu auth login -w <name>` every API command reported not-authenticated
while `cu auth status` (which honoured default_workspace) said otherwise.

Add auth.CurrentWorkspace(), which resolves config default_workspace
(or CU_DEFAULT_WORKSPACE) and falls back to DefaultWorkspace, and route
GetCurrentToken, `auth status` and `auth logout` through it. `auth login`
now records the workspace on both the --token and interactive paths
(previously only interactive), and logging in to the default workspace
after a named one switches back to it.

Closes #23

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timimsms
timimsms merged commit 4d6965f into main Nov 18, 2026
16 checks passed
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.

auth: named-workspace tokens are stored but never used by the API client

1 participant