Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Support locale in message queue (#1447)
Luke Vella7c5f4e3692b7
diff --git a/apps/web/src/app/api/send-email/route.ts b/apps/web/src/app/api/send-email/route.tsindex 4570b7f2e..d54de7cdc 100644--- a/apps/web/src/app/api/send-email/route.ts+++ b/apps/web/src/app/api/send-email/route.ts@@ -1,33 +1,28 @@import * as Sentry from "@sentry/nextjs";-import { verifySignatureAppRouter } from "@upstash/qstash/nextjs";import type { NextRequest } from "next/server";import { NextResponse } from "next/server";import { getEmailClient } from "@/utils/emails";-const emailClient = getEmailClient();+import { verifySignature } from "./verify-signature";-export const POST = async (req: NextRequest) => {- /**- * We need to call verifySignatureAppRouter inside the route handler- * to avoid the build breaking when env vars are not set.- */- return verifySignatureAppRouter(async (req: NextRequest) => {- const body = await req.json();+export const POST = verifySignature(async (req: NextRequest) => {+ const body = await req.json();- // TODO: Add validation for templateName and options+ // TODO: Add validation for templateName and options- try {- await emailClient.sendTemplate(body.templateName, body.options);+ const emailClient = getEmailClient(body.locale);- return NextResponse.json({ success: true });- } catch (error) {- Sentry.captureException(error);+ try {+ await emailClient.sendTemplate(body.templateName, body.options);- return NextResponse.json(- { success: false, error: "Failed to send email" },- { status: 500 },- );- }- })(req);-};+ return NextResponse.json({ success: true });+ } catch (error) {+ Sentry.captureException(error);++ return NextResponse.json(+ { success: false, error: "Failed to send email" },+ { status: 500 },+ );+ }+});diff --git a/apps/web/src/app/api/send-email/verify-signature.ts b/apps/web/src/app/api/send-email/verify-signature.tsnew file mode 100644index 000000000..b94b18544--- /dev/null+++ b/apps/web/src/app/api/send-email/verify-signature.ts@@ -0,0 +1,12 @@+import { verifySignatureAppRouter } from "@upstash/qstash/dist/nextjs";+import type { NextRequest } from "next/server";++export async function verifySignature(+ handler: (req: NextRequest) => Promise<Response>,+) {+ /**+ * We need to call verifySignatureAppRouter inside the route handler+ * to avoid the build breaking when env vars are not set.+ */+ return (req: NextRequest) => verifySignatureAppRouter(handler)(req);+}diff --git a/packages/emails/src/queue.ts b/packages/emails/src/queue.tsindex 1360c5ec4..3ce1739ef 100644--- a/packages/emails/src/queue.ts+++ b/packages/emails/src/queue.ts@@ -5,5 +5,5 @@ export function createQstashClient() {return null;}- return new Client({ token: process.env.QSTASH_TOKEN! });+ return new Client({ token: process.env.QSTASH_TOKEN });}diff --git a/packages/emails/src/send-email.tsx b/packages/emails/src/send-email.tsxindex 4adad1432..90a23366e 100644--- a/packages/emails/src/send-email.tsx+++ b/packages/emails/src/send-email.tsx@@ -83,7 +83,7 @@ export class EmailClient {queue.enqueueJSON({url: absoluteUrl("/api/send-email"),- body: { templateName, options },+ body: { locale: this.config.locale, templateName, options },}).catch(() => {Sentry.captureException(new Error("Failed to queue email"));