-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
37 lines (33 loc) · 960 Bytes
/
proxy.ts
File metadata and controls
37 lines (33 loc) · 960 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
33
34
35
36
37
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
/** Public HTML routes (also excluded from matcher — no edge auth work). */
const isPublicRoute = createRouteMatcher([
'/',
'/sign-in(.*)',
'/sign-up(.*)',
]);
/**
* Public API routes must skip auth.protect() so webhooks and published feeds work.
* All other /api/* requests still run through middleware and require a session.
*/
const isPublicApiRoute = createRouteMatcher([
'/api/webhooks(.*)',
'/api/published(.*)',
'/api/cli(.*)',
]);
export default clerkMiddleware(async (auth, req) => {
const pathname = req.nextUrl.pathname;
if (pathname.startsWith('/api/') && isPublicApiRoute(req)) {
return;
}
if (!isPublicRoute(req)) {
await auth.protect();
}
});
export const config = {
matcher: [
// Docs app + APIs only — skips `/`, auth pages, redirects, and static assets
'/docs/:path*',
'/cli/:path*',
'/api/:path*',
],
};