-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
31 lines (27 loc) · 746 Bytes
/
middleware.js
File metadata and controls
31 lines (27 loc) · 746 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
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function middleware(req) {
console.log("Path:", req.nextUrl.pathname);
console.log("Token:", req.nextauth.token);
// Example role protection for other routes
if (
req.nextUrl.pathname.startsWith("/ClientMember") &&
req.nextauth.token?.role !== "Admin"
) {
return NextResponse.rewrite(new URL("/Denied", req.url));
}
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token }) => !!token, // all matched routes require auth
},
}
);
export const config = {
matcher: [
"/ClientMember",
"/Member", // keep your protected pages here
],
};