Link fixes
commit 56c1608deaf1921a80dc71bcbd107e772dd656f4 Author: Omar López <zomars@me.com> Date: Wed Dec 21 19:26:04 2022 -0700 Update link.ts commit eab43d833515cabc7acf2f973c2d2837ac1a0332 Author: zomars <zomars@me.com> Date: Wed Dec 21 19:03:02 2022 -0700 Prevents 500 on TRPC error commit 3a6970d5e5fab54136b379e1b2ccd7acf515a809 Author: zomars <zomars@me.com> Date: Wed Dec 21 18:15:26 2022 -0700 Encoding fixes
This commit is contained in:
parent
cefcb1eaf8
commit
d0a3d8d144
|
@ -5,6 +5,7 @@ import { z } from "zod";
|
||||||
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
||||||
import { defaultResponder } from "@calcom/lib/server";
|
import { defaultResponder } from "@calcom/lib/server";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
import { TRPCError } from "@calcom/trpc/server";
|
||||||
import { createContext } from "@calcom/trpc/server/createContext";
|
import { createContext } from "@calcom/trpc/server/createContext";
|
||||||
import { viewerRouter } from "@calcom/trpc/server/routers/viewer";
|
import { viewerRouter } from "@calcom/trpc/server/routers/viewer";
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ const decryptedSchema = z.object({
|
||||||
async function handler(req: NextApiRequest, res: NextApiResponse<Response>) {
|
async function handler(req: NextApiRequest, res: NextApiResponse<Response>) {
|
||||||
const { action, token, reason } = querySchema.parse(req.query);
|
const { action, token, reason } = querySchema.parse(req.query);
|
||||||
const { bookingUid, userId } = decryptedSchema.parse(
|
const { bookingUid, userId } = decryptedSchema.parse(
|
||||||
JSON.parse(symmetricDecrypt(token, process.env.CALENDSO_ENCRYPTION_KEY || ""))
|
JSON.parse(symmetricDecrypt(decodeURIComponent(token), process.env.CALENDSO_ENCRYPTION_KEY || ""))
|
||||||
);
|
);
|
||||||
|
|
||||||
/** We shape the session as required by tRPC router */
|
/** We shape the session as required by tRPC router */
|
||||||
|
@ -47,17 +48,24 @@ async function handler(req: NextApiRequest, res: NextApiResponse<Response>) {
|
||||||
where: { uid: bookingUid },
|
where: { uid: bookingUid },
|
||||||
});
|
});
|
||||||
|
|
||||||
/** @see https://trpc.io/docs/server-side-calls */
|
try {
|
||||||
const ctx = await createContext({ req, res }, sessionGetter);
|
/** @see https://trpc.io/docs/server-side-calls */
|
||||||
const caller = viewerRouter.createCaller(ctx);
|
const ctx = await createContext({ req, res }, sessionGetter);
|
||||||
await caller.bookings.confirm({
|
const caller = viewerRouter.createCaller(ctx);
|
||||||
bookingId: booking.id,
|
await caller.bookings.confirm({
|
||||||
recurringEventId: booking.recurringEventId || undefined,
|
bookingId: booking.id,
|
||||||
confirmed: action === DirectAction.ACCEPT,
|
recurringEventId: booking.recurringEventId || undefined,
|
||||||
reason,
|
confirmed: action === DirectAction.ACCEPT,
|
||||||
});
|
reason,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
let message = "Error confirming booking";
|
||||||
|
if (e instanceof TRPCError) message = e.message;
|
||||||
|
res.redirect(`/booking/${bookingUid}?error=${encodeURIComponent(message)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return res.redirect(`/booking/${bookingUid}`);
|
res.redirect(`/booking/${bookingUid}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defaultResponder(handler);
|
export default defaultResponder(handler);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { OrganizerScheduledEmail } from "./OrganizerScheduledEmail";
|
||||||
export const OrganizerRequestEmail = (props: React.ComponentProps<typeof OrganizerScheduledEmail>) => {
|
export const OrganizerRequestEmail = (props: React.ComponentProps<typeof OrganizerScheduledEmail>) => {
|
||||||
const seedData = { bookingUid: props.calEvent.uid, userId: props.calEvent.organizer.id };
|
const seedData = { bookingUid: props.calEvent.uid, userId: props.calEvent.organizer.id };
|
||||||
const token = symmetricEncrypt(JSON.stringify(seedData), process.env.CALENDSO_ENCRYPTION_KEY || "");
|
const token = symmetricEncrypt(JSON.stringify(seedData), process.env.CALENDSO_ENCRYPTION_KEY || "");
|
||||||
const actionHref = `${WEBAPP_URL}/api/link/?token=${token}`;
|
const actionHref = `${WEBAPP_URL}/api/link/?token=${encodeURIComponent(token)}`;
|
||||||
return (
|
return (
|
||||||
<OrganizerScheduledEmail
|
<OrganizerScheduledEmail
|
||||||
title={
|
title={
|
||||||
|
|
Loading…
Reference in New Issue
Block a user