Skip to content

Commit

Permalink
Possibly fix contact email not sending
Browse files Browse the repository at this point in the history
  • Loading branch information
futurGH committed Dec 23, 2023
1 parent 8659945 commit 752e54a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/global/CustomSeo.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export type CustomSeoProps = Partial<DefaultSeoProps> & {
};
export function CustomSeo(props: CustomSeoProps) {
const { data = {}, ...rest } = props;
const { data: { shop: { name, description } = {} } = {}, errors } = useShopQuery<ShopInfoQuery>({
const { data: shopData, errors } = useShopQuery<ShopInfoQuery>({
query: SHOP_INFO_QUERY,
cache: CacheLong(),
preload: "*",
});
const { shop } = shopData ?? {};
const { name, description } = shop ?? {};

if (errors) console.log(errors);

Expand Down
21 changes: 10 additions & 11 deletions src/routes/api/contact.server.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
import type { HydrogenRequest } from "@shopify/hydrogen";

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

const client = new SESClient({
credentials: {
accessKeyId: env.SES_ACCESS_KEY_ID,
secretAccessKey: env.SES_ACCESS_KEY,
},
region: "us-east-1",
});

export async function api(request: HydrogenRequest) {
if (request.method === "GET") return new Response(null, { status: 302, headers: { Location: "/contact-us" } });
if (request.method !== "POST") return new Response(null, { status: 405 });

const client = new SESClient({
credentials: {
accessKeyId: Oxygen.env.SES_ACCESS_KEY_ID,
secretAccessKey: Oxygen.env.SES_ACCESS_KEY,
},
region: "us-east-1",
});

const data = await request.formData();
const { name, email, message, locale, "g-recaptcha-response": recaptchaToken } = Object.fromEntries(data.entries());
if (!name || !email || !message) return new Response(null, { status: 400 });
Expand All @@ -32,7 +30,7 @@ export async function api(request: HydrogenRequest) {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
secret: env.PRIVATE_RECAPTCHA_SECRET_KEY,
secret: Oxygen.env.PRIVATE_RECAPTCHA_SECRET_KEY,
response: recaptchaToken,
}),
});
Expand All @@ -44,6 +42,7 @@ export async function api(request: HydrogenRequest) {
} else {
potentiallySpam = true;
}

const date = new Intl.DateTimeFormat("en-US", {
month: "long",
day: "numeric",
Expand Down

0 comments on commit 752e54a

Please sign in to comment.