-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
42 lines (38 loc) · 1.12 KB
/
Copy pathproxy.ts
File metadata and controls
42 lines (38 loc) · 1.12 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
41
42
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
/** Routes that require sign-in. Unauthenticated users are redirected to sign-in. */
const isProtectedRoute = createRouteMatcher([
"/",
"/dashboard(.*)",
"/profile(.*)",
"/channels(.*)",
"/messages(.*)",
"/admin(.*)",
"/api/admin(.*)",
"/booking(.*)",
"/mentors(.*)",
"/linku-ai(.*)",
"/networking(.*)",
"/notifications(.*)",
"/reviews(.*)",
"/feed(.*)",
"/search(.*)",
"/post(.*)",
]);
/** Admin-only routes: redirect non-admins to dashboard. */
const isAdminRoute = createRouteMatcher(["/admin(.*)", "/api/admin(.*)"]);
export default clerkMiddleware(async (auth, req) => {
if (isProtectedRoute(req)) {
await auth.protect();
}
if (isAdminRoute(req)) {
const { sessionClaims } = await auth();
const role = (sessionClaims?.metadata as { role?: string } | undefined)?.role;
if (role !== "ADMIN") {
return NextResponse.redirect(new URL("/dashboard", req.url));
}
}
});
export const config = {
matcher: ["/((?!_next|.*\\..*).*)", "/", "/(api|trpc)(.*)"]
};