shopify-scopes-sync v1.0.3
Shopify Scopes Sync
The shopify-scopes-sync package ensures that the Shopify access scopes specified in your project's shopify.app.toml file are automatically synchronized with the SCOPES variable in your .env file. This synchronization helps maintain consistency in your development and deployment environments, reducing the risk of scope-related errors in your Shopify applications.
Background: Authentication Works In Local Dev Mode But Not In Production (AWS EC2)
At Site Chat, we wrapped our site and service into a Shopify App using its Remix template. When migrating from local testing to AWS EC2, authentication and billing APIs stopped working, even though they ran fine on a local machine. If you've encountered a similar issue as described on Shopify Community and Shopify Github, the root cause might be that the API access scopes are out of sync in the .env file (production deployment) and the shopify.app.toml (local test). This problem led to the creation of a solution to smoothly sync scopes.
Installation
To install shopify-scopes-sync, run the following command in your project directory:
npm install shopify-scopes-sync --saveor
yarn add shopify-scopes-sync -D -WThis command adds shopify-scopes-sync to your project's dependencies.
Usage
After installing shopify-scopes-sync, you need to add a script to your package.json to run the synchronization process. Here's how to set it up:
- Open your project's
package.jsonfile. - Add a new script named
predeployin thescriptssection: - Update your
deploycommand to ensure that scope is synced.
"scripts": {
"predeploy": "shopify-scopes-sync",
"deploy": "npm run predeploy && shopify app deploy",
}- Save the changes to your
package.jsonfile.
Now, you can run the following command to synchronize your Shopify access scopes:
npm run sync-scopesor
npm run deployThis script executes shopify-scopes-sync, which reads the scopes from your shopify.app.toml and updates the SCOPES variable in your .env file accordingly.
Custom Usage
If your .env or shopify.app.toml files are located in non-standard locations, you can pass the paths to these files as arguments to the script:
"scripts": {
"sync-scopes": "shopify-scopes-sync --env ./path/to/.env --toml ./path/to/shopify.app.toml"
}Replace ./path/to/.env and ./path/to/shopify.app.toml with the actual paths to your files.
Contributing
We welcome contributions to shopify-scopes-sync! If you have suggestions for improvements or encounter any issues, please open an issue or submit a pull request on our GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.