From e01278e05096b752c7eb3d0898e042bfb6f59335 Mon Sep 17 00:00:00 2001 From: NotNite Date: Tue, 25 Apr 2023 20:03:36 -0400 Subject: [PATCH] clean up expiring auth tickets --- src/prisma.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/prisma.ts b/src/prisma.ts index 66f2d50..319b2f4 100644 --- a/src/prisma.ts +++ b/src/prisma.ts @@ -43,8 +43,27 @@ async function refreshDiscordTokens() { } } +async function expireTickets() { + const expired = await prisma.authTicket.findMany({ + where: { + expiresAt: { + lte: new Date() + } + } + }); + + for (const ticket of expired) { + await prisma.authTicket.delete({ + where: { + id: ticket.id + } + }); + } +} + setInterval(async () => { await refreshDiscordTokens(); + await expireTickets(); }, 60 * 1000); export default prisma;