The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update rate limit window to once every minute
Steven Tey0a7e9959c0cf
diff --git a/apps/web/lib/auth/session.ts b/apps/web/lib/auth/session.tsindex c7cb5e15f9..cb784594f4 100644--- a/apps/web/lib/auth/session.ts+++ b/apps/web/lib/auth/session.ts@@ -85,14 +85,27 @@ export const withSession = (handler: WithSessionHandler) =>});}waitUntil(- prisma.token.update({- where: {- hashedKey,- },- data: {- lastUsed: new Date(),- },- }),+ (async () => {+ try {+ // update last used time for the token (only once every minute)+ const { success } = await ratelimit(1, "1 m").limit(+ `last-used-${hashedKey}`,+ );++ if (success) {+ await prisma.token.update({+ where: {+ hashedKey,+ },+ data: {+ lastUsed: new Date(),+ },+ });+ }+ } catch (error) {+ console.error(error);+ }+ })(),);session = {user: {diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.tsindex 793aeb56da..514f32490d 100644--- a/apps/web/lib/auth/workspace.ts+++ b/apps/web/lib/auth/workspace.ts@@ -232,10 +232,10 @@ export const withWorkspace = (}waitUntil(- // update last used time for the token (only once every 15 minutes)+ // update last used time for the token (only once every minute)(async () => {try {- const { success } = await ratelimit(1, "15 m").limit(+ const { success } = await ratelimit(1, "1 m").limit(`last-used-${hashedKey}`,);