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.

Extend cron auth to include qstash calls

Steven Teydaca49422877
diff --git a/apps/web/app/api/cron/usage/route.ts b/apps/web/app/api/cron/usage/route.ts
index 805bebcdd9..e76ba77162 100644
--- a/apps/web/app/api/cron/usage/route.ts
+++ b/apps/web/app/api/cron/usage/route.ts
@@ -1,4 +1,4 @@
-import { verifySignature } from "@/lib/cron";
+import { receiver, verifySignature } from "@/lib/cron";
import { log } from "@dub/utils";
import { NextResponse } from "next/server";
import { updateUsage } from "./utils";
@@ -7,9 +7,18 @@ import { updateUsage } from "./utils";
// Runs once every day at noon UTC (0 12 * * *)
export async function GET(req: Request) {
- const validSignature = await verifySignature(req);
- if (!validSignature) {
- return new Response("Unauthorized", { status: 401 });
+ const body = await req.json();
+ if (process.env.VERCEL === "1") {
+ const validSignature = await verifySignature(req);
+ if (!validSignature) {
+ const isValid = await receiver.verify({
+ signature: req.headers.get("Upstash-Signature") || "",
+ body: JSON.stringify(body),
+ });
+ if (!isValid) {
+ return new Response("Unauthorized", { status: 401 });
+ }
+ }
}
try {