Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

conditionally set bodyType

Steven Tey18d2f218eb66
diff --git a/apps/web/app/api/webhooks/callback/route.ts b/apps/web/app/api/webhooks/callback/route.ts
index 98cc92795c..58a8013997 100644
--- a/apps/web/app/api/webhooks/callback/route.ts
+++ b/apps/web/app/api/webhooks/callback/route.ts
@@ -20,7 +20,7 @@ const searchParamsSchema = z.object({
export const POST = async (req: Request) => {
const rawBody = await req.text();
- await verifyQstashSignature(req, rawBody);
+ await verifyQstashSignature(req, rawBody, "text");
const { url, status, body, sourceBody, sourceMessageId } =
webhookCallbackSchema.parse(JSON.parse(rawBody));
diff --git a/apps/web/lib/cron/verify-qstash.ts b/apps/web/lib/cron/verify-qstash.ts
index a075c8ebcc..834e0e7d98 100644
--- a/apps/web/lib/cron/verify-qstash.ts
+++ b/apps/web/lib/cron/verify-qstash.ts
@@ -7,12 +7,16 @@ const receiver = new Receiver({
nextSigningKey: process.env.QSTASH_NEXT_SIGNING_KEY || "",
});
-export const verifyQstashSignature = async (req: Request, body?: any) => {
- body = body || (await req.text());
+export const verifyQstashSignature = async (
+ req: Request,
+ body: any,
+ bodyType: "json" | "text" = "json",
+) => {
+ body = body || (bodyType === "json" ? await req.json() : await req.text());
const isValid = await receiver.verify({
signature: req.headers.get("Upstash-Signature") || "",
- body,
+ body: bodyType === "json" ? JSON.stringify(body) : body,
});
if (!isValid) {