Skip to content

Commit

Permalink
fix: add redirect shop
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 8, 2023
1 parent acd575c commit ec2ccd1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function redirectAuth() {
{ status: 401, headers: { "content-type": "application/json" } }
);
}
function redirectShop(req: NextRequest) {
console.error("Account Limited");
return NextResponse.redirect(new URL("/shop", req.url));
}

export async function middleware(req: NextRequest, context: NextFetchEvent) {
try {
Expand All @@ -40,15 +44,16 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {
);
console.log(`use user apiKey ${ipIdentifier}, remaining: ${remaining}`);
if (!success) {
return redirectAuth();
return redirectShop(req);
}

return NextResponse.next();
}

// 3. something-invalid-sdalkjfasncs-key
if (!(await validateLicenseKey(userKey, cacheId))) {
return redirectAuth();
const isValidatedLicense = await validateLicenseKey(userKey, cacheId);
if (!isValidatedLicense) {
return redirectShop(req);
}
}

Expand Down Expand Up @@ -79,7 +84,7 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {
);
console.log(`login user ${userEmail}, remaining: ${remaining}`);
if (!success) {
return redirectAuth();
return redirectShop(req);
}

return res;
Expand Down

1 comment on commit ec2ccd1

@vercel
Copy link

@vercel vercel bot commented on ec2ccd1 Mar 8, 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.