diff --git a/app/layout.tsx b/app/layout.tsx index 53a79f925..6dc05ea08 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -8,8 +8,8 @@ const { TWITTER_CREATOR, TWITTER_SITE, SITE_NAME } = process.env; const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : 'http://localhost:3000'; -const twitterCreator = ensureStartsWith(TWITTER_CREATOR, '@'); -const twitterSite = ensureStartsWith(TWITTER_SITE, 'https://'); +const twitterCreator = TWITTER_CREATOR ? ensureStartsWith(TWITTER_CREATOR, '@') : undefined; +const twitterSite = TWITTER_SITE ? ensureStartsWith(TWITTER_SITE, 'https://') : undefined; export const metadata = { metadataBase: new URL(baseUrl), diff --git a/lib/shopify/index.ts b/lib/shopify/index.ts index e03ae8ed9..0b14212d2 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -50,7 +50,9 @@ import { ShopifyUpdateCartOperation } from './types'; -const domain = ensureStartsWith(process.env.SHOPIFY_STORE_DOMAIN, 'https://') || ''; +const domain = process.env.SHOPIFY_STORE_DOMAIN + ? ensureStartsWith(process.env.SHOPIFY_STORE_DOMAIN, 'https://') + : ''; const endpoint = `${domain}${SHOPIFY_GRAPHQL_API_ENDPOINT}`; const key = process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN!; diff --git a/lib/utils.ts b/lib/utils.ts index d3a16d092..02ff6fe1b 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -7,8 +7,5 @@ export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyUR return `${pathname}${queryString}`; }; -export const ensureStartsWith = (stringToCheck?: string, startsWith?: string) => { - if (!stringToCheck || !startsWith) return stringToCheck; - - return stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`; -}; +export const ensureStartsWith = (stringToCheck: string, startsWith: string) => + stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;