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.

Add a cron job to remove expired public tokens

Kiran K483f5b7ad521
diff --git a/apps/web/app/api/cron/cleanup-expired-public-tokens/route.ts b/apps/web/app/api/cron/cleanup-expired-public-tokens/route.ts
new file mode 100644
index 0000000000..dc12eb412b
--- /dev/null
+++ b/apps/web/app/api/cron/cleanup-expired-public-tokens/route.ts
@@ -0,0 +1,32 @@
+import { handleAndReturnErrorResponse } from "@/lib/api/errors";
+import { verifyVercelSignature } from "@/lib/cron/verify-vercel";
+import { prisma } from "@/lib/prisma";
+import { log } from "@dub/utils";
+import { NextResponse } from "next/server";
+
+export const dynamic = "force-dynamic";
+
+// Cron to remove the expired public embed tokens
+// Run every day (0 12 * * *)
+export async function GET(req: Request) {
+ try {
+ await verifyVercelSignature(req);
+
+ await prisma.embedPublicToken.deleteMany({
+ where: {
+ expires: {
+ lt: new Date(),
+ },
+ },
+ });
+
+ return NextResponse.json({ status: "OK" });
+ } catch (error) {
+ await log({
+ message: `Links and domain cleanup failed - ${error.message}`,
+ type: "errors",
+ });
+
+ return handleAndReturnErrorResponse(error);
+ }
+}
diff --git a/apps/web/vercel.json b/apps/web/vercel.json
index ba487b5a45..8f9ffe21e6 100644
--- a/apps/web/vercel.json
+++ b/apps/web/vercel.json
@@ -15,6 +15,10 @@
{
"path": "/api/cron/disposable-emails",
"schedule": "0 12 * * 1"
+ },
+ {
+ "path": "/api/cron/cleanup-expired-public-tokens",
+ "schedule": "0 12 * * *"
}
],
"functions": {