Refactor API route validation in middleware.ts

This commit is contained in:
Kiran K 2023-11-21 10:06:02 +05:30
parent 8be2e20f90
commit f23eb97161
1 changed files with 1 additions and 3 deletions

View File

@ -19,7 +19,6 @@ const unAuthenticatedApiRoutes = [
'/api/setup/**',
'/api/branding',
'/api/scim/cron/**',
// '/api/internals/product/**',
];
export async function middleware(req: NextRequest) {
@ -45,8 +44,7 @@ export async function middleware(req: NextRequest) {
}
// Validate API routes `/api/v1/**`
// Question: Is it okay to use same API key?
if (micromatch.isMatch(pathname, ['/api/v1/**', '/api/internals/product/**'])) {
if (micromatch.isMatch(pathname, ['/api/v1/**', '/api/internals/**'])) {
if (!validateApiKey(extractAuthToken(req))) {
return sendUnAuthorizedResponse({ message: 'Unauthorized' });
}