diff --git a/src/app/api/stores/[storeId]/route.ts b/src/app/api/stores/[storeId]/route.ts index 84977bf..00caac2 100644 --- a/src/app/api/stores/[storeId]/route.ts +++ b/src/app/api/stores/[storeId]/route.ts @@ -144,7 +144,12 @@ export async function PATCH( // Even if ScriptTag operations fail (missing scopes), the widget still // won’t render because /api/storefront-chat/config returns the flag. try { - const appBaseUrl = (process.env.NEXT_PUBLIC_APP_URL || "").trim() + const appBaseUrl = ( + process.env.NEXT_PUBLIC_APP_URL || + process.env.AUTH_URL || + process.env.NEXTAUTH_URL || + "" + ).trim() const apiVersion = "2024-01" const injectorBase = appBaseUrl ? appBaseUrl.replace(/\/$/, "") : "" diff --git a/src/app/storefront-chat/widget-injector/route.ts b/src/app/storefront-chat/widget-injector/route.ts index 04cbb6f..24e3d75 100644 --- a/src/app/storefront-chat/widget-injector/route.ts +++ b/src/app/storefront-chat/widget-injector/route.ts @@ -11,7 +11,11 @@ export async function GET() { try { var script = document.currentScript; var baseUrl = script && script.src ? new URL(script.src).origin : window.location.origin; - var shop = window.location.hostname; + // Prefer Shopify-provided shop identifier when available. + // On custom domains, window.location.hostname won't match the shop's myshopify domain. + var shop = + (window.Shopify && (window.Shopify.shop || window.Shopify.myshopifyDomain)) || + window.location.hostname; var containerId = "juno-storefront-chat-container"; var iframeId = "juno-storefront-chat-iframe";