The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add resend endpoint
Steven Tey7d9bec64fc68
diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.tsindex dc24ffacc2..27062dac84 100644--- a/apps/web/app/api/user/route.ts+++ b/apps/web/app/api/user/route.ts@@ -56,6 +56,17 @@ export const DELETE = withSession(async ({ session }) => {cloudinary.v2.uploader.destroy(`avatars/${session?.user?.id}`, {invalidate: true,}),+ // Disabling this until there's a way to delete audience by email using Resend API+ // fetch(+ // `https://api.resend.com/audiences/${process.env.RESEND_AUDIENCE_ID}/contacts`,+ // {+ // method: "DELETE",+ // headers: {+ // Authorization: `Bearer ${process.env.RESEND_API_KEY}`,+ // "Content-Type": "application/json",+ // },+ // },+ // )]);const response = await prisma.user.delete({where: {diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.tsindex 718c7a6e43..dbeffdc2b7 100644--- a/apps/web/emails/index.ts+++ b/apps/web/emails/index.ts@@ -27,8 +27,8 @@ export const sendEmail = async ({}return resend.emails.send({from: marketing- ? "Steven from Dub <[email protected]>"- : "Dub <[email protected]>",+ ? "Steven from Dub.co <[email protected]>"+ : "Dub.co <[email protected]>",to: test ? "[email protected]" : email,subject,react,diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.tsindex 85265b60ae..154efba84c 100644--- a/apps/web/lib/auth/options.ts+++ b/apps/web/lib/auth/options.ts@@ -298,15 +298,32 @@ export const authOptions: NextAuthOptions = {user?.createdAt &&new Date(user.createdAt).getTime() > Date.now() - 10000) {- sendEmail({- subject: "Welcome to Dub.co!",- email,- react: WelcomeEmail({+ await Promise.allSettled([+ fetch(+ `https://api.resend.com/audiences/${process.env.RESEND_AUDIENCE_ID}/contacts`,+ {+ method: "POST",+ headers: {+ Authorization: `Bearer ${process.env.RESEND_API_KEY}`,+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ email,+ first_name: user.name?.split(" ")[0] || null,+ last_name: user.name?.split(" ")[1] || null,+ }),+ },+ ),+ sendEmail({+ subject: "Welcome to Dub.co!",email,- name: user.name || null,+ react: WelcomeEmail({+ email,+ name: user.name || null,+ }),+ marketing: true,}),- marketing: true,- });+ ]);}}},diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prismaindex b40b621277..7fa7db07f3 100644--- a/apps/web/prisma/schema.prisma+++ b/apps/web/prisma/schema.prisma@@ -23,7 +23,7 @@ model User {sessions Session[]projects ProjectUsers[]links Link[]- tokens Token[]+ tokens Token[]createdAt DateTime @default(now())}diff --git a/apps/web/scripts/get-users.ts b/apps/web/scripts/get-users.tsnew file mode 100644index 0000000000..abbeeae122--- /dev/null+++ b/apps/web/scripts/get-users.ts@@ -0,0 +1,50 @@+import "dotenv-flow/config";+import prisma from "@/lib/prisma";+import fs from "fs";++async function main() {+ const unsubscribedUsers = await fetch(+ `https://api.resend.com/audiences/${process.env.RESEND_AUDIENCE_ID}/contacts`,+ {+ method: "GET",+ headers: {+ Authorization: `Bearer ${process.env.RESEND_API_KEY}`,+ "Content-Type": "application/json",+ },+ },+ ).then((res) => res.json());++ const unsubscribedUserEmails = unsubscribedUsers.data.map(+ (user) => user.email,+ );++ const users = await prisma.user.findMany({+ select: {+ email: true,+ name: true,+ createdAt: true,+ },+ where: {+ email: {+ notIn: unsubscribedUserEmails,+ },+ },+ });+ const processedUsers = users.map(({ email, name, createdAt }) => ({+ email,+ firstName: name?.split(" ")[0] || "",+ lastName: name?.split(" ")[1] || "",+ createdAt: createdAt.toISOString(),+ }));++ // write to csv file, with headers+ const csv = [+ ["Email", "First Name", "Last Name", "Joined"].join(","),+ ...processedUsers.map(({ email, firstName, lastName, createdAt }) =>+ [email, firstName, lastName, createdAt].join(","),+ ),+ ].join("\n");+ fs.writeFileSync("users.csv", csv);+}++main();