Skip to content

feat: update auth flow#19

Merged
scmmishra merged 5 commits into
mainfrom
feat/update-auth-flow
Jun 3, 2026
Merged

feat: update auth flow#19
scmmishra merged 5 commits into
mainfrom
feat/update-auth-flow

Conversation

@scmmishra
Copy link
Copy Markdown
Member

Two improvements to auth login and how the CLI stores credentials.

Separate dev credentials

Dev builds (go build -tags dev / mise run dev) now use their own config file and keyring, so iterating on the CLI never reads, overwrites, or deletes the credentials of an installed prod binary.

  • prod: ~/.chatwoot/config.yaml + keyring service chatwoot-cli
  • dev: ~/.chatwoot/config.dev.yaml + keyring service chatwoot-cli-dev

The dev path is gated behind the dev build tag and is compiled out of release builds entirely. config view shows a Profile: dev line on dev builds.

Verify account access at login

auth login validated the API token but not that it could access the account ID you entered — a wrong/typo'd account was saved anyway and only failed later as a 404 on the first call. Login now checks the account against the profile's membership list and rejects up front, naming the accounts the key can access. Instances that don't return accounts are unaffected.

Tests

  • Build-profile guards (prod + dev) and a keyring-isolation regression test
  • Account-verification unit test + a full auth login integration test
  • Green under both go test ./... and go test -tags dev ./...

scmmishra added 4 commits June 2, 2026 19:55
The dev build profile shared keyringService="chatwoot-cli" with prod and
only varied the entry name, but DeleteAPIKey calls DeleteAll(keyringService).
A dev `auth logout` therefore erased the prod login's token (and vice versa),
breaking the separate-credentials guarantee.

Namespace the keyring service per build profile ("chatwoot-cli" for prod,
"chatwoot-cli-dev" for dev) so DeleteAll stays scoped to the active build while
keeping its "wipe stale entries" behavior. The entry name is shared again.

Add build-profile guards (prod/dev) and a logout-isolation regression test, and
derive the legacy-config test path from ConfigPath() so the package passes under
-tags dev too.
`auth login` validated the API token via /api/v1/profile but never checked
that the token could access the account ID the user entered. A wrong or
mistyped account was saved anyway and only surfaced later as a cryptic 404 on
the first account-scoped call.

Parse the accounts membership list already returned by the profile endpoint and
reject login when the entered account is not among them, naming the accounts the
key can access. Instances that return no accounts are left unaffected.
@scmmishra scmmishra marked this pull request as ready for review June 3, 2026 08:28
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

⚠️ Note: Baseline coverage from main branch is not available (artifact may be expired). Showing current coverage for changed files only.

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/chatwoot/cli/internal/cmd 45.81% (+45.81%) 🌟
github.com/chatwoot/cli/internal/config 73.56% (+73.56%) 🌟
github.com/chatwoot/cli/internal/sdk 56.25% (+56.25%) 🌟

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/chatwoot/cli/internal/cmd/auth.go 71.72% (+71.72%) 99 (+99) 71 (+71) 28 (+28) 🌟
github.com/chatwoot/cli/internal/cmd/config.go 47.83% (+47.83%) 23 (+23) 11 (+11) 12 (+12) 🌟
github.com/chatwoot/cli/internal/config/config.go 64.10% (+64.10%) 39 (+39) 25 (+25) 14 (+14) 🌟
github.com/chatwoot/cli/internal/config/credentials.go 81.25% (+81.25%) 48 (+48) 39 (+39) 9 (+9) 🌟
github.com/chatwoot/cli/internal/config/profile_dev.go 0.00% (ø) 0 0 0
github.com/chatwoot/cli/internal/config/profile_prod.go 0.00% (ø) 0 0 0
github.com/chatwoot/cli/internal/sdk/profile.go 75.00% (+75.00%) 4 (+4) 3 (+3) 1 (+1) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/chatwoot/cli/internal/cmd/auth_test.go
  • github.com/chatwoot/cli/internal/config/config_test.go
  • github.com/chatwoot/cli/internal/config/credentials_test.go
  • github.com/chatwoot/cli/internal/config/profile_dev_test.go
  • github.com/chatwoot/cli/internal/config/profile_prod_test.go

@scmmishra scmmishra merged commit 3bf6405 into main Jun 3, 2026
10 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.

1 participant