Skip to content

fix(cli): auth recovery for stale keys and clearer 401 UX#286

Open
leggetter wants to merge 3 commits intomainfrom
fix/cli-auth-login-recovery
Open

fix(cli): auth recovery for stale keys and clearer 401 UX#286
leggetter wants to merge 3 commits intomainfrom
fix/cli-auth-login-recovery

Conversation

@leggetter
Copy link
Copy Markdown
Collaborator

Summary

Improves how the CLI behaves when credentials are missing, invalid, or expired: users and agents get clearer messages, hookdeck login can recover from a rejected stored key without a separate logout, and noisy log output for expected 401s is reduced.

Changes

  • 401 handling in Execute(): Map API unauthorized errors to a short, actionable message (stdout for normal CLI; stderr only for hookdeck gateway mcp so JSON-RPC on stdout stays clean). Suggests hookdeck login, -i, --api-key, and MCP reauth.
  • HTTP client: Add hookdeck.IsUnauthorizedError. Log 401 responses at debug instead of error so default runs are not flooded with Unexpected response for expected bad keys (still diagnosable with --log-level debug).
  • hookdeck login: If GET /cli-auth/validate returns 401, stop the verify spinner, print Your saved API key is no longer valid. Starting browser sign-in..., clear the in-memory key, and continue the existing browser/device flow.
  • Config: ResetAPIClient() after a successful browser login so a long-lived process picks up the new key; ResetAPIClientForTesting delegates to it.
  • Tests: Unit tests for IsUnauthorizedError and login 401→browser flow; basic acceptance tests (mock API for login recovery; real API for ci with invalid key—fast fail, no browser phrases).

Type of change

User-facing behavior and messaging (fix / UX improvement; login recovery is a small feature in behavior terms). Suggested release note: patch-level unless you treat login recovery as minor.

How to verify

  • hookdeck whoami with a bad key → friendly message, no ERROR log line at default --log-level.
  • hookdeck login with stale config key → message then browser/device flow.
  • hookdeck ci --api-key <invalid> → quick failure, no interactive login copy.
  • go test ./... and basic acceptance slice including new tests.

Made with Cursor

leggetter and others added 3 commits April 9, 2026 13:26
- Map API 401s to a friendly message in Execute(); gateway MCP prints it to stderr only.

- Log 401 responses at debug in the HTTP client to reduce noisy errors for whoami and agents.

- Add hookdeck.IsUnauthorizedError for consistent detection.

- login: if /cli-auth/validate returns 401, clear the stale in-memory key and continue into the browser/device flow.

- Reset the cached API client after a successful browser login so the same process uses the new key.

- Tests: hookdeck client + login unit tests; basic acceptance (mock login after 401, ci invalid key fast-fail without browser phrases).

Made-with: Cursor
…tting

Replace exported ResetAPIClient with RefreshCachedAPIClient that updates the singleton in place (matches how MCP already mutates credentials on the shared *hookdeck.Client). Keep resetAPIClient unexported for tests only.

MCP login continues to assign client.APIKey/ProjectID explicitly: tests use a dedicated client pointer, not the global singleton.

Made-with: Cursor
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