Skip to content

Conversation

@gonzaloriestra
Copy link
Contributor

@gonzaloriestra gonzaloriestra commented Oct 7, 2025

WHY are these changes introduced?

Fixes https://github.com/shop/issues-develop/issues/21223

We keep seeing some unhandled 401 errors like this, that shouldn't be happening.

When the CLI gets a 401, it tries to get a new token (by refreshing or starting the full authentication flow) and then retries the request.

The problem is that the retry after the refresh process was always using the App Management API token, but if the query was against Business Platform API, then it was obviously getting another 401, that was reported.

WHAT is this pull request doing?

Pass the API type to the refresh function, so that it returns the proper token for each one.

How to test your changes?

The token must become invalid right before a Business Platform request, so it's not easy to reproduce. I faked it this way:

  • Add a breakpoint here
  • Run p shopify app dev
  • When it the debugger stops, update the value of appContextResult.developerPlatformClient.session.businessPlatformToken to wrong
  • Continue
  • On main, it should return a 401. With this branch, it should work.

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@gonzaloriestra
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.96% (-0.01% 🔻)
13315/16862
🟡 Branches
72.66% (+0.02% 🔼)
6505/8953
🟡 Functions
79.15% (-0.04% 🔻)
3440/4346
🟡 Lines
79.33% (-0% 🔻)
12578/15856
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / Dev.tsx
90.59% (-2.35% 🔻)
75% (-1.79% 🔻)
86.36% (-4.55% 🔻)
92.5% (-1.25% 🔻)
🔴
... / app-management-client.ts
53.29% (-0.55% 🔻)
46.79% (-0.34% 🔻)
49.54% (-0.91% 🔻)
52.09% (-0.61% 🔻)
🔴
... / partners-client.ts
24.7% (-1.77% 🔻)
26.09% (-3.08% 🔻)
17.74% (-2.57% 🔻)
24.53% (-1.85% 🔻)
🟢
... / session.ts
94.23% (-0.21% 🔻)
95.12%
87.5% (-2.5% 🔻)
94.23% (-0.21% 🔻)

Test suite run success

3237 tests passing in 1337 suites.

Report generated by 🧪jest coverage report action from 3e52bb5

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20251007130258

Caution

After installing, validate the version by running just shopify in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@gonzaloriestra gonzaloriestra marked this pull request as ready for review October 7, 2025 13:37
@gonzaloriestra gonzaloriestra requested a review from a team as a code owner October 7, 2025 13:37
@github-actions

This comment has been minimized.

@gonzaloriestra gonzaloriestra requested a review from a team as a code owner October 8, 2025 07:59
@gonzaloriestra gonzaloriestra added this pull request to the merge queue Oct 8, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 8, 2025
@gonzaloriestra gonzaloriestra added this pull request to the merge queue Oct 8, 2025
Merged via the queue into main with commit abed43c Oct 8, 2025
2 checks passed
@gonzaloriestra gonzaloriestra deleted the fix-token-refresh-on-bp branch October 8, 2025 09:06
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.

3 participants