Skip to content

Commit

Permalink
feat: added USER_LICENSE_KEYS
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 2, 2023
1 parent b20f6ce commit 58ee334
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
OPENAI_API_KEY=
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
USER_LICENSE_KEYS=
9 changes: 9 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export async function middleware(req: NextRequest, ev: NextFetchEvent) {
const identifier = req.ip ?? "127.0.0.3";
const { success, remaining } = await ratelimit.limit(identifier);
console.log(`======== ip ${identifier}, remaining: ${remaining} ========`);

// note: not forgot to set USER_LICENSE_KEYS env var
if (process.env.USER_LICENSE_KEYS?.includes(apiKey)) {
const { remaining } = await ratelimit.limit(apiKey);
if (remaining === 0) {
return NextResponse.redirect(new URL("/blocked", req.url));
}
}

if (!apiKey && !success) {
return NextResponse.redirect(new URL("/blocked", req.url));
}
Expand Down

1 comment on commit 58ee334

@vercel
Copy link

@vercel vercel bot commented on 58ee334 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.