Template
Default the store domain to mock.shop when unset
An unset or blank VITE_SHOPIFY_DOMAIN reached the Hydrogen client as an empty storeDomain, which throws 'storeDomain is required and must be non-empty'. Fall back to the tokenless mock.shop store instead, and only send the public token alongside a configured domain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
968a243bd4
commit
099ba454e0
@@ -58,7 +58,7 @@ export const storefront = createStorefrontClient({
|
||||
type: 'public',
|
||||
requestContext,
|
||||
config: {
|
||||
storeDomain: SHOPIFY_STORE_DOMAIN!,
|
||||
storeDomain: SHOPIFY_STORE_DOMAIN,
|
||||
apiVersion: SHOPIFY_API_VERSION,
|
||||
publicStorefrontToken: SHOPIFY_PUBLIC_ACCESS_TOKEN,
|
||||
fetch: storefrontFetch,
|
||||
|
||||
@@ -2,15 +2,25 @@
|
||||
//
|
||||
// These are all `VITE_*`, so Vite inlines them at build time and they are safe
|
||||
// to read from the browser bundle as well as the Hono server.
|
||||
export const SHOPIFY_STORE_DOMAIN = import.meta.env.VITE_SHOPIFY_DOMAIN;
|
||||
const CONFIGURED_STORE_DOMAIN = import.meta.env.VITE_SHOPIFY_DOMAIN?.trim();
|
||||
|
||||
/**
|
||||
* Store domain, falling back to the tokenless `mock.shop` demo store when the
|
||||
* variable is unset or blank — the Storefront client rejects an empty domain.
|
||||
*/
|
||||
export const SHOPIFY_STORE_DOMAIN = CONFIGURED_STORE_DOMAIN || 'mock.shop';
|
||||
|
||||
/**
|
||||
* Public Storefront API access token. Safe to expose to the browser — that is
|
||||
* what "public" means here. Omitted for tokenless storefronts such as
|
||||
* `mock.shop`. Never put a *private* token behind a `VITE_` name.
|
||||
*
|
||||
* Only used alongside a configured domain: a token belongs to one store, so it
|
||||
* is never sent to the `mock.shop` fallback.
|
||||
*/
|
||||
export const SHOPIFY_PUBLIC_ACCESS_TOKEN = import.meta.env
|
||||
.VITE_SHOPIFY_PUBLIC_ACCESS_TOKEN;
|
||||
export const SHOPIFY_PUBLIC_ACCESS_TOKEN = CONFIGURED_STORE_DOMAIN
|
||||
? import.meta.env.VITE_SHOPIFY_PUBLIC_ACCESS_TOKEN?.trim() || undefined
|
||||
: undefined;
|
||||
|
||||
export const SHOPIFY_API_VERSION =
|
||||
import.meta.env.VITE_SHOPIFY_API_VERSION || '2026-07';
|
||||
|
||||
Reference in New Issue
Block a user