Repository navigation
fix(auth): use the configured workspace token in the API client - #61
Merged
Merged
Conversation
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>
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.
Summary
Manager.GetCurrentToken()always read thedefaultkeyring account, ignoring configdefault_workspace, whilecu auth statushonoured it. Aftercu auth login -w <name>every API command reported not-authenticated even thoughauth statussaid authenticated.auth.CurrentWorkspace()resolves configdefault_workspace(soCU_DEFAULT_WORKSPACEalso works via viper's env binding), falling back toauth.DefaultWorkspace.GetCurrentToken()(used byapi.NewClientandcu api),cu auth statusandcu auth logout(when-wis omitted) all resolve through it, so they can't disagree.cu auth login -w <name>now recordsdefault_workspaceon the--tokenpath too. Before this, only the interactive path did, sologin -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 plaincu auth loginwith no prior named workspace still writes no config file.auth loginhelp text now explains what--workspacedoes;docs/site/commands/cu_auth_login.mdregenerated (only the meaningful hunk is committed).--workspaceflag. The only-wflags are onauth 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, thenapi.NewClient()succeeds,auth status -o jsonreportsprod, andauth logoutremoves 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.shpasses locally (orgo test -race ./...at minimum)feat:,fix:,docs:,chore:,ci:,test:)cu docs markdown --dir docs/site/commands)🤖 Generated with Claude Code