From c24f5200f52a40fc962a650ecec9b6e400789665 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Wed, 7 Jun 2023 02:34:06 +0530 Subject: [PATCH] fix: opt in booking from email (#9358) * fix: opt in booking from email Signed-off-by: Udit Takkar * fix: undo this Signed-off-by: Udit Takkar * fix: type error Signed-off-by: Udit Takkar * fix: type error Signed-off-by: Udit Takkar * fix: Avada Kedavra type errors Signed-off-by: Udit Takkar --------- Signed-off-by: Udit Takkar Co-authored-by: Peer Richelsen --- apps/web/pages/api/link.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/web/pages/api/link.ts b/apps/web/pages/api/link.ts index efae23bb33..9a0ebdba51 100644 --- a/apps/web/pages/api/link.ts +++ b/apps/web/pages/api/link.ts @@ -26,7 +26,7 @@ const decryptedSchema = z.object({ async function handler(req: NextApiRequest, res: NextApiResponse) { const { action, token, reason } = querySchema.parse(req.query); - const { bookingUid } = decryptedSchema.parse( + const { bookingUid, userId } = decryptedSchema.parse( JSON.parse(symmetricDecrypt(decodeURIComponent(token), process.env.CALENDSO_ENCRYPTION_KEY || "")) ); @@ -34,10 +34,19 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { where: { uid: bookingUid }, }); + const user = await prisma.user.findUniqueOrThrow({ + where: { id: userId }, + }); + try { /** @see https://trpc.io/docs/server-side-calls */ const ctx = await createContext({ req, res }); - const caller = viewerRouter.createCaller({ ...ctx, req, res }); + const caller = viewerRouter.createCaller({ + ...ctx, + req, + res, + user: { ...user, locale: user?.locale ?? "en" }, + }); await caller.bookings.confirm({ bookingId: booking.id, recurringEventId: booking.recurringEventId || undefined,