-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
executable file
·62 lines (50 loc) · 2 KB
/
middleware.js
File metadata and controls
executable file
·62 lines (50 loc) · 2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";
export async function middleware(req) {}
// const session = await getToken({ req, secret: process.env.AUTH_SECRET });
// const userRole = session?.user?.roles || [];
// const { pathname, searchParams } = req.nextUrl;
// if (pathname.startsWith('/dashboard')) {
// if (!session) return NextResponse.redirect(new URL('/', req.url));
// const allowedRoles = ['admin', 'super'];
// if (
// !Array.isArray(userRole) ||
// !userRole.some((role) => allowedRoles.includes(role))
// )
// return NextResponse.redirect(new URL('/', req.url));
// }
// if (pathname.startsWith('/dashboard/user/create')) {
// const allowedRoles = ['super'];
// if (
// !Array.isArray(userRole) ||
// !userRole.some((role) => allowedRoles.includes(role))
// )
// return NextResponse.redirect(new URL('/', req.url));
// }
// if (pathname.startsWith('/post/create') && searchParams.get('id')) {
// if (!session) return NextResponse.redirect(new URL('/', req.url));
// const userId = searchParams.get('id');
// if (userId !== session.user.id)
// return NextResponse.redirect(new URL('/', req.url));
// }
// if (pathname.startsWith('/post/edit') && searchParams.get('id')) {
// if (!session) return NextResponse.redirect(new URL('/', req.url));
// const id = searchParams.get("id");
// const authorId = await prisma.post.findUnique({
// where: { id },
// select: { authorId: true },
// });
// console.log("authorid from middleware", authorId);
// if (authorId !== session.user.id)
// return NextResponse.redirect(new URL("/", req.url));
// }
// if (pathname.startsWith("/post") && searchParams.get("id")) {
// if (!session) return NextResponse.redirect(new URL("/", req.url));
// const userId = searchParams.get("id");
// if (userId !== session.user.id)
// return NextResponse.redirect(new URL("/", req.url));
// }
// }
// export const config = {
// matcher: ['/dashboard/:path*', '/post/:path*'],
// };