Skip to content

fix: token logic for getCliClient()#322

Merged
binoy14 merged 2 commits intomainfrom
01-22-fix_fixes_issue_with_token_logic
Jan 23, 2026
Merged

fix: token logic for getCliClient()#322
binoy14 merged 2 commits intomainfrom
01-22-fix_fixes_issue_with_token_logic

Conversation

@binoy14
Copy link
Contributor

@binoy14 binoy14 commented Jan 23, 2026

Fixes issue with the token and requireUser logic which broke telemetry reporting (mostly).

The issue was that if you have requireUser: false then it does not look up stored token and without token API call to check telemetry consent fails. This fixes that logic to use provided or look it up always.

Also added extensive tests for apiClient

@claude
Copy link

claude bot commented Jan 23, 2026

Claude finished @binoy14's task in 1m 4s —— View job


Code Review Complete

  • Read modified apiClient.ts
  • Read new test file
  • Review diff against main
  • Analyze token logic fix
  • Check test coverage and quality
  • Post review findings

Review Findings

The PR successfully fixes the token lookup logic. The code and tests look solid with 100% coverage. No issues found that require fixing.

The fix correctly addresses the problem where requireUser: false would skip token lookup entirely, breaking telemetry. Now tokens are always retrieved (if not provided), which is the correct behavior.

Test coverage is comprehensive and includes all critical paths including edge cases for both client types, error scenarios, and middleware behavior.

Copy link
Contributor Author

binoy14 commented Jan 23, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

github-actions bot commented Jan 23, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.07% 5702 / 8023
🔵 Statements 70.41% 5850 / 8308
🔵 Functions 59.12% 875 / 1480
🔵 Branches 58.78% 2523 / 4292
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/@sanity/cli-core/src/services/apiClient.ts 100% 100% 100% 100%
Generated in workflow #1664 for commit b5ecfcf by the Vitest Coverage Report Action

@binoy14 binoy14 marked this pull request as ready for review January 23, 2026 03:39
@binoy14 binoy14 requested a review from a team as a code owner January 23, 2026 03:39
@binoy14 binoy14 requested review from rexxars and removed request for a team January 23, 2026 03:39
@binoy14 binoy14 force-pushed the 01-22-fix_fixes_issue_with_token_logic branch from caf890c to b5ecfcf Compare January 23, 2026 04:22
Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this technically already "works as intended" - sometimes you want to send unauthenticated requests, and with this that is no longer a possibility, I think?

@binoy14
Copy link
Contributor Author

binoy14 commented Jan 23, 2026

To me this technically already "works as intended" - sometimes you want to send unauthenticated requests, and with this that is no longer a possibility, I think?

In a way yes, but this is different from the current CLI logic and it breaks the telemetry calls. The problem is that telemetry has requireUser: false so current it does not attach token and fails with 401 due to missing authorization.

@binoy14 binoy14 requested a review from rexxars January 23, 2026 20:26
Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@rexxars rexxars changed the title fix: fixes issue with token logic fix: token logic for getCliClient() Jan 23, 2026
@binoy14 binoy14 merged commit d62eeda into main Jan 23, 2026
23 checks passed
@binoy14 binoy14 deleted the 01-22-fix_fixes_issue_with_token_logic branch January 23, 2026 22:44
@squiggler-legacy squiggler-legacy bot mentioned this pull request Jan 23, 2026
@squiggler-app squiggler-app bot mentioned this pull request Mar 6, 2026
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.

2 participants