-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
32 lines (28 loc) · 848 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
32 lines (28 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
// Define your public routes
const isPublicRoute = createRouteMatcher([
'/',
'/collabrate(.*)',
'/publish(.*)',
'/preview(.*)',
'/clsign-in(.*)', // Sign-in page (already public)
'/sign-up(.*)',
'/api/edgestore(.*)',
'/api/notes(.*)',
]);
export default clerkMiddleware(async (auth, request) => {
// Skip authentication for public routes
if (isPublicRoute(request)) {
return;
}
// Protect all other routes
await auth.protect();
});
export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_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)(.*)',
],
};