Skip to content

Commit

Permalink
fix: allow use user's apiKey
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 2, 2023
1 parent 1d575df commit 6e970f4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const ratelimit = new Ratelimit({
});

export async function middleware(req: NextRequest, ev: NextFetchEvent) {
const { bvId } = await req.json();
const { bvId, apiKey } = await req.json();
// TODO: unique to a user (userid, email etc) instead of IP
const identifier = req.ip ?? "127.0.0.2";
const { success, remaining } = await ratelimit.limit(identifier);
console.log(`======== ip ${identifier}, remaining: ${remaining} ========`);
if (!success) {
if (!apiKey && !success) {
return NextResponse.redirect(new URL("/blocked", req.url));
}

Expand Down

1 comment on commit 6e970f4

@vercel
Copy link

@vercel vercel bot commented on 6e970f4 Mar 2, 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.