Skip to content

cio auth status reports stale account_id when CIO_TOKEN env var overrides cached config #19

@sud0n1m

Description

@sud0n1m

Bug

cio auth status reports the account_id from ~/.cio/config.json even when CIO_TOKEN env var is set with a token from a different account. The actual API calls correctly use the env-var token (so the bug is purely in the status display, not in auth dispatch), but it makes debugging cross-account setups very confusing — a user can be looking at account_id: A in auth status while every API call goes to account B.

Reproduction

  1. cio auth login --with-token with a token for account A (cached to ~/.cio/config.json with account_id A).
  2. export CIO_TOKEN=<token-for-account-B> where B ≠ A.
  3. cio auth status reports:
    • account_id: Awrong, that's from the cached config
    • token: <last 4 chars match token B> — correct, matches env var
    • token_source: environment — correct, confirms env var is being used
  4. cio api /v1/accounts/B succeeds — confirms API dispatch uses the env-var token correctly.
  5. cio api /v1/accounts/A succeeds too if token B has access to A, but account.email returns B's email — confirming the active principal is B, not A.

After cio auth logout followed by echo \$CIO_TOKEN | cio auth login --with-token, the cached config is rewritten with the correct account_id and cio auth status then reports correctly.

Expected behavior

When token_source: environment, cio auth status should derive account_id from the env-var token (e.g., decode the JWT after exchange, or call a self-introspection endpoint) rather than reading it from the cached config — or at minimum surface a warning that the env-var token may belong to a different account than the displayed account_id.

Context

Discovered while working with two service-account tokens in parallel (a global one in ~/.cio/config.json and a project-scoped one piped in via CIO_TOKEN from .dev.vars). The display mismatch was very confusing — I spent a while convinced the wrong token was being used before realizing API calls were going to the right account all along.

Environment

  • @customerio/cli 0.0.4 (installed via npm i -g @customerio/cli)
  • macOS (Darwin 25.4.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions