-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
40 lines (34 loc) · 1.23 KB
/
Copy pathmiddleware.ts
File metadata and controls
40 lines (34 loc) · 1.23 KB
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
39
40
// import { NextRequest, NextResponse } from "next/server";
// This function can be marked `async` if using `await` inside
// export function middleware(request: NextRequest, response: NextResponse) {
// // add a canonical link header to the response
// response.headers.set("Link", '<https://example.com>; rel="canonical"');
// return NextResponse.next();
// }
// See "Matching Paths" below to learn more
// export const config = {
// matcher: ["/about/:path*", "/dashboard/:path*"],
// };
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
const isProtectedRoute = createRouteMatcher([
"/dashboard(.*)",
"/forum(.*)",
"/admin(.*)",
]);
export default clerkMiddleware((auth, req) => {
req.headers.set("Link", '<https://nxt-lms.vercel.app>; rel="canonical"');
if (isProtectedRoute(req)) {
// auth().protect((has) => {
// return has({ role: "admin" });
// });
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)(.*)",
],
};