Skip to content

Commit

Permalink
Remove env variable that would fallback to import.meta from Oxygen to…
Browse files Browse the repository at this point in the history
… hopefully prevent undefined env vars
  • Loading branch information
futurGH committed Dec 23, 2023
1 parent 752e54a commit 0c35ed3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/lib/ReCaptcha.client.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { GoogleReCaptchaProvider } from "react-google-recaptcha-v3";
import type { ReactNode } from "react";

const env: Record<string, string> = typeof Oxygen !== "undefined" && "env" in Oxygen ? Oxygen.env : import.meta.env;

export function ReCaptcha({ children }: { children: ReactNode }) {
return <GoogleReCaptchaProvider reCaptchaKey={env.PUBLIC_RECAPTCHA_SITE_KEY}>{children}</GoogleReCaptchaProvider>;
return (
<GoogleReCaptchaProvider
reCaptchaKey={Oxygen?.env?.PUBLIC_RECAPTCHA_SITE_KEY || import.meta.env.PUBLIC_RECAPTCHA_SITE_KEY}>
{children}
</GoogleReCaptchaProvider>
);
}
5 changes: 2 additions & 3 deletions src/lib/gqlAdminApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// reference: https://github.com/Shopify/hydrogen/pull/1788/files#diff-4d536ffe12775c4364d272c9fb3d1675c5119d01cffec3e3cddd6b67bb299ade
const env: Record<string, string> = typeof Oxygen !== "undefined" && "env" in Oxygen ? Oxygen.env : import.meta.env;
export async function adminApiClient<T>(query: string, variables: Record<string, unknown> = {}): Promise<T> {
const endpoint = `https://${env.STOREFRONT_NAME}.myshopify.com/admin/api/${env.ADMIN_API_VERSION}/graphql.json`;
const endpoint = `https://${Oxygen.env.STOREFRONT_NAME}.myshopify.com/admin/api/${Oxygen.env.ADMIN_API_VERSION}/graphql.json`;
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": env.ADMIN_API_TOKEN,
"X-Shopify-Access-Token": Oxygen.env.ADMIN_API_TOKEN,
},
body: JSON.stringify({ query, variables }),
});
Expand Down

0 comments on commit 0c35ed3

Please sign in to comment.