The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
make the RESEND_API_KEY optional
Kiran K42a88151516b
diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.tsindex adacaa3413..d7a90acd88 100644--- a/apps/web/emails/index.ts+++ b/apps/web/emails/index.ts@@ -18,21 +18,14 @@ export const sendEmail = async ({marketing?: boolean;}) => {if (process.env.NODE_ENV === "development" && !resend) {- // Set up a fake email client for developmentconsole.info(- `Email to ${email} with subject ${subject} sent from ${- from || process.env.NEXT_PUBLIC_APP_NAME- }`,- );- return Promise.resolve();- } else if (!resend) {- console.error(- "Resend is not configured. You need to add a RESEND_API_KEY in your .env file for emails to work.",+ "RESEND_API_KEY is not set in the .env. Skipping sending email.",);+return Promise.resolve();}- return resend.emails.send({+ return resend?.emails.send({to: email,from:from ||diff --git a/apps/web/lib/resend.ts b/apps/web/lib/resend.tsindex 9b3a27956a..b465b4d44b 100644--- a/apps/web/lib/resend.ts+++ b/apps/web/lib/resend.ts@@ -1,6 +1,8 @@import { Resend } from "resend";-export const resend = new Resend(process.env.RESEND_API_KEY);+const resendApiKey = process.env.RESEND_API_KEY;++export const resend = resendApiKey ? new Resend(resendApiKey) : null;export async function subscribe({email,@@ -9,12 +11,14 @@ export async function subscribe({email: string;name?: string | null;}) {- if (!process.env.RESEND_API_KEY || !process.env.RESEND_AUDIENCE_ID) {- console.error("Resend API key or audience ID not found");+ const audienceId = process.env.RESEND_AUDIENCE_ID;++ if (!audienceId) {+ console.error("RESEND_AUDIENCE_ID is not set in the .env. Skipping.");return;}- return await resend.contacts.create({+ return await resend?.contacts.create({email,...(name && {firstName: name.split(" ")[0],@@ -25,7 +29,7 @@ export async function subscribe({}export async function unsubscribe({ email }: { email: string }) {- return await resend.contacts.remove({+ return await resend?.contacts.remove({email,audienceId: process.env.RESEND_AUDIENCE_ID as string,});diff --git a/apps/web/ui/analytics/feedback/action.ts b/apps/web/ui/analytics/feedback/action.tsindex 96fc610d33..9f3056d0b5 100644--- a/apps/web/ui/analytics/feedback/action.ts+++ b/apps/web/ui/analytics/feedback/action.ts@@ -7,7 +7,7 @@ export async function submitFeedback(data: FormData) {const email = data.get("email") as string;const feedback = data.get("feedback") as string;- return await resend.emails.send({+ return await resend?.emails.send({from: "[email protected]",to: "[email protected]",...(email && { replyTo: email }),