Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add unsubscribeUrl to welcome emails

Steven Tey5ab77e04a95a
diff --git a/apps/web/app/(ee)/api/cron/welcome-user/route.ts b/apps/web/app/(ee)/api/cron/welcome-user/route.ts
index d6c3574f80..f411b40f7a 100644
--- a/apps/web/app/(ee)/api/cron/welcome-user/route.ts
+++ b/apps/web/app/(ee)/api/cron/welcome-user/route.ts
@@ -1,9 +1,11 @@
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
+import { generateUnsubscribeToken } from "@/lib/email/unsubscribe-token";
import { sendEmail } from "@dub/email";
import WelcomeEmail from "@dub/email/templates/welcome-email";
import WelcomeEmailPartner from "@dub/email/templates/welcome-email-partner";
import { prisma } from "@dub/prisma";
+import { APP_DOMAIN, PARTNERS_DOMAIN } from "@dub/utils";
export const dynamic = "force-dynamic";
@@ -40,6 +42,8 @@ export async function POST(req: Request) {
const isPartner = user.partners.length > 0;
+ const unsubscribeUrl = `${isPartner ? PARTNERS_DOMAIN : APP_DOMAIN}/unsubscribe/${generateUnsubscribeToken(user.email)}`;
+
await Promise.allSettled([
sendEmail({
to: user.email,
@@ -49,10 +53,12 @@ export async function POST(req: Request) {
? WelcomeEmailPartner({
email: user.email,
name: user.name,
+ unsubscribeUrl,
})
: WelcomeEmail({
email: user.email,
name: user.name,
+ unsubscribeUrl,
}),
variant: "marketing",
}),
diff --git a/packages/email/src/templates/welcome-email-partner.tsx b/packages/email/src/templates/welcome-email-partner.tsx
index fe3fab0e0f..bd4ca71b4b 100644
--- a/packages/email/src/templates/welcome-email-partner.tsx
+++ b/packages/email/src/templates/welcome-email-partner.tsx
@@ -18,9 +18,11 @@ import { Footer } from "../components/footer";
export default function WelcomeEmailPartner({
name = "Brendon Urie",
email = "[email protected]",
+ unsubscribeUrl,
}: {
name: string | null;
email: string;
+ unsubscribeUrl: string;
}) {
return (
<Html>
@@ -116,7 +118,7 @@ export default function WelcomeEmailPartner({
</Link>
</Section>
- <Footer email={email} marketing />
+ <Footer email={email} marketing unsubscribeUrl={unsubscribeUrl} />
</Container>
</Body>
</Tailwind>
diff --git a/packages/email/src/templates/welcome-email.tsx b/packages/email/src/templates/welcome-email.tsx
index b182e1590a..f5ae7c3777 100644
--- a/packages/email/src/templates/welcome-email.tsx
+++ b/packages/email/src/templates/welcome-email.tsx
@@ -18,9 +18,11 @@ import { Footer } from "../components/footer";
export default function WelcomeEmail({
name = "Brendon Urie",
email = "[email protected]",
+ unsubscribeUrl,
}: {
name: string | null;
email: string;
+ unsubscribeUrl: string;
}) {
return (
<Html>
@@ -119,7 +121,7 @@ export default function WelcomeEmail({
</Link>
</Section>
- <Footer email={email} marketing />
+ <Footer email={email} marketing unsubscribeUrl={unsubscribeUrl} />
</Container>
</Body>
</Tailwind>