Enable authentication errors to display store names
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}` : '.') +
...
}
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
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
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
mainyou might see odd diffs, rebasemaininto 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
/snapit
π«°β¨ 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
ETARGETerror, install it with NPM and the flag--@shopify:registry=https://registry.npmjs.org
[!CAUTION] After installing, validate the version by running just
shopifyin your terminal. If the versions don't match, you might have multiple global instances installed. Usewhich shopifyto find out which one you are running and uninstall it.