Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide token warning in mock.shop #1538

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-bikes-confess.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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