Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fix email not being sent in user’s preferred language (#2037)

Luke Vellafacfe53befa9
diff --git a/apps/web/src/app/api/trpc/[trpc]/route.ts b/apps/web/src/app/api/trpc/[trpc]/route.ts
index 8f0a7323e..44d726991 100644
--- a/apps/web/src/app/api/trpc/[trpc]/route.ts
+++ b/apps/web/src/app/api/trpc/[trpc]/route.ts
@@ -5,6 +5,7 @@ import { ipAddress } from "@vercel/functions";
import type { NextRequest } from "next/server";
import { getSession } from "@/lib/auth";
+import { getLocaleFromRequest } from "@/lib/locale/server";
import type { TRPCContext } from "@/trpc/context";
import { appRouter } from "@/trpc/routers";
import { getEmailClient } from "@/utils/emails";
@@ -13,6 +14,7 @@ const handler = async (req: NextRequest) => {
const session = await getSession();
const ip = ipAddress(req);
const ja4Digest = req.headers.get("x-vercel-ja4-digest");
+ const reqLocale = getLocaleFromRequest(req);
return fetchRequestHandler({
endpoint: "/api/trpc",
@@ -26,7 +28,7 @@ const handler = async (req: NextRequest) => {
? {
id: session.user.id,
isGuest: session.user.isGuest,
- locale: session.user.locale ?? undefined,
+ locale: session.user.locale ?? reqLocale,
image: session.user.image ?? undefined,
getEmailClient: () =>
getEmailClient(session.user?.locale ?? undefined),
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 1359b3061..d741deb33 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -183,8 +183,6 @@ export const participants = router({
)
.mutation(
async ({ ctx, input: { pollId, votes, name, email, timeZone } }) => {
- const { user } = ctx;
-
const { participant, totalResponses } = await prisma.$transaction(
async (prisma) => {
const participantCount = await prisma.participant.count({
@@ -207,10 +205,10 @@ export const participants = router({
name: name,
email,
timeZone,
- ...(user.isLegacyGuest
- ? { guestId: user.id }
- : { userId: user.id }),
- locale: user.locale ?? undefined,
+ ...(ctx.user.isLegacyGuest
+ ? { guestId: ctx.user.id }
+ : { userId: ctx.user.id }),
+ locale: ctx.user.locale ?? undefined,
},
include: {
poll: {
@@ -256,7 +254,7 @@ export const participants = router({
if (email) {
const token = await createToken(
- { userId: user.id },
+ { userId: ctx.user.id },
{
ttl: 0, // basically forever
},