mirror of
https://github.com/Rohithgilla12/data-peek
synced 2026-05-18 15:08:30 +00:00
35 lines
903 B
TypeScript
35 lines
903 B
TypeScript
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'
|
|
|
|
// Define which routes require authentication
|
|
const isProtectedRoute = createRouteMatcher([
|
|
'/account(.*)',
|
|
'/api/account(.*)',
|
|
])
|
|
|
|
// Define which routes are public API endpoints (no auth needed)
|
|
const isPublicApiRoute = createRouteMatcher([
|
|
'/api/license/(.*)',
|
|
'/api/updates/(.*)',
|
|
'/api/webhooks/(.*)',
|
|
])
|
|
|
|
export default clerkMiddleware(async (auth, req) => {
|
|
// Skip auth for public API routes
|
|
if (isPublicApiRoute(req)) {
|
|
return
|
|
}
|
|
|
|
// Protect dashboard routes
|
|
if (isProtectedRoute(req)) {
|
|
await auth.protect()
|
|
}
|
|
})
|
|
|
|
export const config = {
|
|
matcher: [
|
|
// Skip Next.js internals and all static files
|
|
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
|
|
// Always run for API routes
|
|
'/(api|trpc)(.*)',
|
|
],
|
|
}
|