-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
33 lines (26 loc) · 769 Bytes
/
middleware.ts
File metadata and controls
33 lines (26 loc) · 769 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";
const isPublicRoute = createRouteMatcher([
"/",
"/signin(.*)",
"/signup(.*)",
"/sso-callback(.*)",
"/assets(.*)",
"/api/upload(.*)",
]);
// API routes handle their own auth - don't redirect from middleware
const isApiRoute = createRouteMatcher(["/api(.*)"]);
export default clerkMiddleware((auth, req) => {
// Skip protection for public routes
if (isPublicRoute(req)) {
return;
}
// API routes handle their own auth - don't call protect() which throws NEXT_NOT_FOUND
if (isApiRoute(req)) {
return;
}
// Protect page routes (non-API)
auth.protect();
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};