From 1789aef7d3319e48700a85787367dd5e3e0250be Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:40:42 +0530 Subject: [PATCH] fix: organizer req email v2 issue (#20314) --- apps/web/app/api/verify-booking-token/route.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/app/api/verify-booking-token/route.ts b/apps/web/app/api/verify-booking-token/route.ts index 3ecf29775d..3bb909e873 100644 --- a/apps/web/app/api/verify-booking-token/route.ts +++ b/apps/web/app/api/verify-booking-token/route.ts @@ -42,7 +42,7 @@ async function getHandler(request: NextRequest) { ); } - return await handleBookingAction(action, token, bookingUid, userId, undefined, request); + return await handleBookingAction(action, token, bookingUid, userId, request, undefined); } catch (error) { const bookingUid = queryParams.bookingUid || ""; return NextResponse.redirect( @@ -60,7 +60,7 @@ async function postHandler(request: NextRequest) { const body = await parseRequestData(request).catch(() => ({})); const { reason } = z.object({ reason: z.string().optional() }).parse(body || {}); - return await handleBookingAction(action, token, bookingUid, userId, reason, request); + return await handleBookingAction(action, token, bookingUid, userId, request, reason); } catch (error) { const bookingUid = queryParams.bookingUid || ""; return NextResponse.redirect( @@ -74,16 +74,17 @@ async function handleBookingAction( token: string, bookingUid: string, userId: string, - reason?: string, - request?: NextRequest + request: NextRequest, + reason?: string ) { + const url = new URL(request.url); const booking = await prisma.booking.findUnique({ where: { oneTimePassword: token }, }); if (!booking) { return NextResponse.redirect( - `/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}` + `${url.origin}/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}` ); } @@ -139,7 +140,7 @@ async function handleBookingAction( } catch (e) { let message = "Error confirming booking"; if (e instanceof TRPCError) message = (e as TRPCError).message; - return NextResponse.redirect(`/booking/${booking.uid}?error=${encodeURIComponent(message)}`); + return NextResponse.redirect(`${url.origin}/booking/${booking.uid}?error=${encodeURIComponent(message)}`); } await prisma.booking.update({ @@ -147,7 +148,7 @@ async function handleBookingAction( data: { oneTimePassword: null }, }); - return NextResponse.redirect(`/booking/${booking.uid}`); + return NextResponse.redirect(`${url.origin}/booking/${booking.uid}`); } export const GET = defaultResponderForAppDir(getHandler);