-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmiddleware.js
36 lines (22 loc) · 998 Bytes
/
middleware.js
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
import { authMiddleware } from "@clerk/nextjs";
// import { auth } from "clerk"
export default authMiddleware({
publicRoutes: ["/", '/api/role'],
afterAuth(auth, req) {
// if (auth.sessionClaims?.metadata.role === undefined && req.nextUrl.pathname.startsWith("/role") == false) {
// return Response.redirect(new URL('/role', req.url))
// }
// if (auth.sessionClaims?.metadata.role !== undefined && req.nextUrl.pathname.startsWith("/role")) {
// return Response.redirect(new URL('/', req.url))
// }
// if (auth.sessionClaims?.metadata.role !== "teacher" && req.nextUrl.pathname.startsWith("/teacher")) {
// return Response.redirect(new URL('/', req.url))
// }
// if (auth.sessionClaims?.metadata.role !== "student" && req.nextUrl.pathname.startsWith("/student")) {
// return Response.redirect(new URL('/', req.url))
// }
},
});
export const config = {
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};