Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update welcome email
Marc Seitza3b1dc6a02ae
diff --git a/app/api/cron/welcome-user/route.ts b/app/api/cron/welcome-user/route.tsnew file mode 100644index 00000000..4c5ff86f--- /dev/null+++ b/app/api/cron/welcome-user/route.ts@@ -0,0 +1,56 @@+import { verifyQstashSignature } from "@/lib/cron/verify-qstash";+import { sendWelcomeEmail } from "@/lib/emails/send-welcome";+import prisma from "@/lib/prisma";+import { subscribe } from "@/lib/resend";++export const dynamic = "force-dynamic";++export async function POST(req: Request) {+ try {+ const rawBody = await req.text();+ await verifyQstashSignature({ req, rawBody });++ const { userId } = JSON.parse(rawBody);++ const user = await prisma.user.findUnique({+ where: {+ id: userId,+ },+ select: {+ name: true,+ email: true,+ },+ });++ if (!user) {+ return new Response("User not found. Skipping...", { status: 200 });+ }++ // this shouldn't happen but just in case+ if (!user.email) {+ return new Response("User email not found. Skipping...", { status: 200 });+ }++ await Promise.allSettled([+ // send welcome email+ sendWelcomeEmail({+ user: {+ email: user.email,+ name: user.name,+ },+ }),+ // subscribe user to the mailing list+ subscribe(user.email),+ ]);++ return new Response("Welcome email sent and user subscribed.", {+ status: 200,+ });+ } catch (error) {+ console.error(error);+ return new Response(+ "Error sending welcome email and subscribing user to mailing list.",+ { status: 500 },+ );+ }+}diff --git a/lib/emails/send-welcome.ts b/lib/emails/send-welcome.tsindex 04e8edd3..9ae7f9e1 100644--- a/lib/emails/send-welcome.ts+++ b/lib/emails/send-welcome.ts@@ -10,7 +10,7 @@ export const sendWelcomeEmail = async (params: CreateUserEmailProps) => {try {await sendEmail({to: email as string,- from: "Marc from Papermark <[email protected]>",+ marketing: true,subject: "Welcome to Papermark!",react: emailTemplate,test: process.env.NODE_ENV === "development",diff --git a/lib/resend.ts b/lib/resend.tsindex 80adc85e..175b7be4 100644--- a/lib/resend.ts+++ b/lib/resend.ts@@ -48,13 +48,13 @@ export const sendEmail = async ({const fromAddress =from ??(marketing- ? "Marc from Papermark <[email protected]>"+ ? "Marc from Papermark <[email protected]>": system- ? "Papermark <[email protected]>"+ ? "Papermark <[email protected]>": verify- ? "Papermark <[email protected]>"+ ? "Papermark <[email protected]>": !!scheduledAt- ? "Marc Seitz <[email protected]>"+ ? "Marc Seitz <[email protected]>": "Marc from Papermark <[email protected]>");try {@@ -62,7 +62,7 @@ export const sendEmail = async ({from: fromAddress,to: test ? "[email protected]" : to,cc: cc,- replyTo: marketing ? "[email protected]" : replyTo,+ replyTo: marketing ? "[email protected]" : replyTo,subject,react,scheduledAt,diff --git a/lib/webhook/send-webhooks.ts b/lib/webhook/send-webhooks.tsindex eb36b626..58311d30 100644--- a/lib/webhook/send-webhooks.ts+++ b/lib/webhook/send-webhooks.ts@@ -37,7 +37,6 @@ const publishWebhookEventToQStash = async ({webhook: Pick<Webhook, "pId" | "url" | "secret">;payload: WebhookPayload;}) => {- // TODO: add proper domain like app.papermark.dev in devconst callbackUrl = new URL(`${process.env.NEXT_PUBLIC_BASE_URL}/api/webhooks/callback`,);diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsindex 55cbdfd4..6566f0e0 100644--- a/pages/api/auth/[...nextauth].ts+++ b/pages/api/auth/[...nextauth].ts@@ -9,14 +9,15 @@ import GoogleProvider from "next-auth/providers/google";import LinkedInProvider from "next-auth/providers/linkedin";import { identifyUser, trackAnalytics } from "@/lib/analytics";+import { qstash } from "@/lib/cron";import { dub } from "@/lib/dub";import { isBlacklistedEmail } from "@/lib/edge-config/blacklist";import { sendVerificationRequestEmail } from "@/lib/emails/send-verification-request";import { sendWelcomeEmail } from "@/lib/emails/send-welcome";import hanko from "@/lib/hanko";import prisma from "@/lib/prisma";-import { CreateUserEmailProps, CustomUser } from "@/lib/types";import { subscribe } from "@/lib/resend";+import { CreateUserEmailProps, CustomUser } from "@/lib/types";import { log } from "@/lib/utils";import { generateChecksum } from "@/lib/utils/generate-checksum";import { getIpAddress } from "@/lib/utils/ip";@@ -170,13 +171,6 @@ export const authOptions: NextAuthOptions = {},events: {async createUser(message) {- const params: CreateUserEmailProps = {- user: {- name: message.user.name,- email: message.user.email,- },- };-await identifyUser(message.user.email ?? message.user.id);await trackAnalytics({event: "User Signed Up",@@ -184,11 +178,13 @@ export const authOptions: NextAuthOptions = {userId: message.user.id,});- await sendWelcomeEmail(params);-- if (message.user.email) {- await subscribe(message.user.email);- }+ await qstash.publishJSON({+ url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/cron/welcome-user`,+ body: {+ userId: message.user.id,+ },+ delay: 15 * 60, // 15 minutes+ });},},};