cli icon indicating copy to clipboard operation
cli copied to clipboard

Enable authentication errors to display store names

Open dejmedus opened this issue 7 months ago β€’ 4 comments

Fixes #452

WHY are these changes introduced?

Previously users hitting an authentication error wouldn't know which store they were trying to authenticate against. This is because we preserve --store values locally and don't show the user which we're operating against.

WHAT is this pull request doing?

Added store to the tokenRequest params in requestAppToken:

const params = {
  ...
  ...(api === 'admin' && {destination: `https://${store}/admin`, store}),
}

Modified tokenRequest to return both error and store:

return err({error: payload.error, store: params.store})

Updated tokenRequestErrorHandler to use store in the invalid target error message (if store is defined):

function tokenRequestErrorHandler({error, store}: {error: string; store?: string}) {
  const invalidTargetErrorMessage =
     'You are not authorized to use the CLI to develop in the provided store' +
    (store ? `: ${store}` : '.') +
    ...
}
error-message

How to test your changes?

  • Pull down the branch
  • Build the branch
  • Run a theme command on a store you don't have access to: pnpm shopify theme info --store=unathenticated.myshopify.com
  • It should display You are not authorized to use the CLI to develop in the provided store: unathenticated.myshopify.com

Measuring impact

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

  • [x] 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

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

dejmedus avatar May 09 '25 00:05 dejmedus

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
76.63% (+0% πŸ”Ό)
9586/12510
🟑 Branches
71.92% (-0.02% πŸ”»)
4731/6578
🟑 Functions 76.56% 2485/3246
🟑 Lines
77.14% (+0.01% πŸ”Ό)
9059/11744
Show files with reduced coverage πŸ”»
St.:grey_question:
File Statements Branches Functions Lines
🟒
... / loader.ts
93.2% (+0.18% πŸ”Ό)
85% (-0.15% πŸ”»)
97.2%
94.23% (+0.2% πŸ”Ό)
🟒
... / link.ts
96.55%
92.42% (-0.43% πŸ”»)
100% 96.39%
🟒
... / mkcert.ts
93.33% (-3.28% πŸ”»)
76% (-7.87% πŸ”»)
100%
93.02% (-5.22% πŸ”»)
πŸ”΄
... / app-management-client.ts
41.78% (-0.4% πŸ”»)
36.75% (-2.59% πŸ”»)
40%
40.37% (-0.44% πŸ”»)
🟒
... / version.ts
88.89% (-0.58% πŸ”»)
90% 100%
87.5% (-0.74% πŸ”»)

Test suite run success

2252 tests passing in 982 suites.

Report generated by πŸ§ͺjest coverage report action from 6517e437913ad8e1336ee6f40423bb5afb85daa8

github-actions[bot] avatar May 09 '25 00:05 github-actions[bot]

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/private/node/session/exchange.d.ts
@@ -1,4 +1,5 @@
 import { ApplicationToken, IdentityToken } from './schema.js';
+import { API } from '../api.js';
 import { Result } from '../../../public/node/result.js';
 import { ExtendableError } from '../../../public/node/error.js';
 export declare class InvalidGrantError extends ExtendableError {
@@ -61,4 +62,7 @@ type IdentityDeviceError = 'authorization_pending' | 'access_denied' | 'expired_
  * @returns An instance with the identity access tokens.
  */
 export declare function exchangeDeviceCodeForAccessToken(deviceCode: string): Promise<Result<IdentityToken, IdentityDeviceError>>;
+export declare function requestAppToken(api: API, token: string, scopes?: string[], store?: string): Promise<{
+    [x: string]: ApplicationToken;
+}>;
 export {};
\ No newline at end of file

github-actions[bot] avatar May 09 '25 17:05 github-actions[bot]

/snapit

dejmedus avatar May 09 '25 17:05 dejmedus

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

Test the snapshot by installing your package globally:

pnpm i -g @shopify/[email protected]

[!TIP] If you get an ETARGET error, install it with NPM and the flag --@shopify:registry=https://registry.npmjs.org

[!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.

github-actions[bot] avatar May 09 '25 17:05 github-actions[bot]