From 1ad14283ad11354c96257d291e4c4700e2cf79a9 Mon Sep 17 00:00:00 2001 From: JimmyLv Date: Tue, 7 Mar 2023 14:11:41 +0800 Subject: [PATCH] fix: open the limit to 5 --- lib/upstash.ts | 4 ++-- middleware.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/upstash.ts b/lib/upstash.ts index a77cb365..aab202ab 100644 --- a/lib/upstash.ts +++ b/lib/upstash.ts @@ -1,6 +1,6 @@ import { Ratelimit } from "@upstash/ratelimit"; import { Redis } from "@upstash/redis"; -import { FREE_LIMIT_COUNT } from "~/utils/constants"; +import { FREE_LIMIT_COUNT, LOGIN_LIMIT_COUNT } from "~/utils/constants"; export const ratelimit = new Ratelimit({ redis: new Redis({ @@ -8,6 +8,6 @@ export const ratelimit = new Ratelimit({ token: process.env.UPSTASH_RATE_REDIS_REST_TOKEN, }), // 速率限制算法 https://github.com/upstash/ratelimit#ratelimiting-algorithms - limiter: Ratelimit.fixedWindow(FREE_LIMIT_COUNT, "1 d"), + limiter: Ratelimit.fixedWindow(LOGIN_LIMIT_COUNT, "1 d"), analytics: true, // <- Enable analytics }); diff --git a/middleware.ts b/middleware.ts index acac9d4d..5b97af63 100644 --- a/middleware.ts +++ b/middleware.ts @@ -55,7 +55,7 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) { const userEmail = session?.user.email; if (userEmail) { // Authentication successful, forward request to protected route. - const { success, remaining } = await ratelimit.limit(userEmail + "2"); + const { success, remaining } = await ratelimit.limit(userEmail); console.log( `======== user ${userEmail}, remaining: ${remaining} ========` );