-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathclerk.middleware.ts
More file actions
38 lines (34 loc) · 891 Bytes
/
clerk.middleware.ts
File metadata and controls
38 lines (34 loc) · 891 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
38
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
const isPubliclyAccessibleRoute = createRouteMatcher([
// all pages except the ones listed below are protected
"/login(.*)",
"/registration(.*)",
"/.well-known(.*)",
"/authorize(.*)",
"/oauth(.*)",
"/userinfo",
"/revoke",
"/device_authorization",
"/keys",
"/end_session",
"/endsession",
"/oidc(.*)",
"/mcp(.*)"
]);
export default clerkMiddleware(
(auth, request) => {
// Protect all routes except the ones listed above
// https://clerk.com/docs/references/nextjs/clerk-middleware#protect-all-routes
if (!isPubliclyAccessibleRoute(request)) {
auth().protect();
}
return NextResponse.next();
},
{
debug: true
}
);
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"]
};