From 10c70359aa9d5eeb5d1513b0e6ea6bfac970c3a9 Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Tue, 25 Aug 2026 16:53:19 +0330 Subject: [PATCH] Point production login/checkout at customer.sanihome.ir. Stop baking the local Vite URL into storefront builds when CUSTOMER_ORIGIN is unset. Co-authored-by: Cursor --- .env.production | 6 ++++++ src/lib/customer-auth.ts | 33 ++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 .env.production diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..409e170 --- /dev/null +++ b/.env.production @@ -0,0 +1,6 @@ +# Used by `next build` on the websites VM (production). +# Local `next dev` still prefers `.env.local`. +NEXT_PUBLIC_API_BASE_URL=https://api.meshkee.com/api/v1 +NEXT_PUBLIC_DOMAIN=sanihome.ir +NEXT_PUBLIC_CUSTOMER_ORIGIN=https://customer.sanihome.ir +NEXT_PUBLIC_BUSINESS_ORIGIN=https://business.sanihome.ir diff --git a/src/lib/customer-auth.ts b/src/lib/customer-auth.ts index 34fc3be..9b3edcb 100644 --- a/src/lib/customer-auth.ts +++ b/src/lib/customer-auth.ts @@ -4,27 +4,42 @@ import { DOMAIN } from "@/lib/meshkee"; /** * Shared checkout lives on the customer dashboard (all websites). - * Local: http://customer.sanihome.com:5175 - * Prod: https://customer.sanihome.com + * Local: http://customer.{domain}:5175 + * Prod: https://customer.{domain} + * + * Prefer NEXT_PUBLIC_CUSTOMER_ORIGIN. Otherwise derive from DOMAIN + build mode + * so production deploys never bake in the local Vite URL. */ -export const CUSTOMER_ORIGIN = - process.env.NEXT_PUBLIC_CUSTOMER_ORIGIN?.replace(/\/$/, "") || - "http://customer.sanihome.com:5175"; +function resolveCustomerOrigin(): string { + const configured = process.env.NEXT_PUBLIC_CUSTOMER_ORIGIN?.replace(/\/$/, ""); + if (configured) return configured; + + if (process.env.NODE_ENV === "production") { + return `https://customer.${DOMAIN}`; + } + + return `http://customer.${DOMAIN}:5175`; +} + +export const CUSTOMER_ORIGIN = resolveCustomerOrigin(); /** * Business dashboard for website admins. - * Local: http://business.sanihome.com:5173 + * Local: http://business.{domain}:5173 * Prod: https://business.{domain} */ export function businessDashboardUrl(): string { const configured = process.env.NEXT_PUBLIC_BUSINESS_ORIGIN?.replace(/\/$/, ""); if (configured) return `${configured}/`; + if (process.env.NODE_ENV === "production") { + return `https://business.${DOMAIN}/`; + } + if (typeof window !== "undefined") { const { protocol, port } = window.location; - if (port === "3000" || port === "3001" || port === "") { - const portSuffix = port === "3000" || port === "3001" ? ":5173" : ""; - return `${protocol}//business.${DOMAIN}${portSuffix}/`; + if (port === "3000" || port === "3001") { + return `${protocol}//business.${DOMAIN}:5173/`; } }