Skip to content

Commit

Permalink
Hide token warning in mock.shop (#1538)
Browse files Browse the repository at this point in the history
* Skip private token warning when using mock.shop

* Changesets

* Fix repo name in package-lock
  • Loading branch information
frandiox committed Dec 6, 2023
1 parent 33c9b73 commit 62f6787
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-bikes-confess.md
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen-react': patch
---

Skip private access token warning when using mock.shop.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
@@ -1,4 +1,5 @@
{
"name": "hydrogen",
"private": true,
"sideEffects": false,
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions packages/hydrogen-react/src/storefront-client.ts
Expand Up @@ -17,6 +17,8 @@ export type StorefrontClientProps = {
contentType?: 'json' | 'graphql';
};

const isMockShop = (domain: string): boolean => domain.includes('mock.shop');

/**
* The `createStorefrontClient()` function creates helpers that enable you to quickly query the Shopify Storefront API.
*
Expand Down Expand Up @@ -48,7 +50,12 @@ export function createStorefrontClient(
}

// only warn if not in a browser environment
if (__HYDROGEN_DEV__ && !privateStorefrontToken && !globalThis.document) {
if (
__HYDROGEN_DEV__ &&
!privateStorefrontToken &&
!globalThis.document &&
!isMockShop(storeDomain)
) {
warnOnce(
`Using a private storefront token is recommended for server environments.` +
`\nRefer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details.`,
Expand All @@ -63,7 +70,6 @@ export function createStorefrontClient(
);
}

const isMockShop = (domain: string): boolean => domain.includes('mock.shop');
const getShopifyDomain: StorefrontClientReturn['getShopifyDomain'] = (
overrideProps,
) => {
Expand Down

0 comments on commit 62f6787

Please sign in to comment.