Skip to content

Commit

Permalink
fix: open the limit to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 7, 2023
1 parent 316d073 commit 1ad1428
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/upstash.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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({
url: process.env.UPSTASH_RATE_REDIS_REST_URL,
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
});
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} ========`
);
Expand Down

1 comment on commit 1ad1428

@vercel
Copy link

@vercel vercel bot commented on 1ad1428 Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.