forked from pinkycollie/ai.mbtq.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
34 lines (30 loc) · 876 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
34 lines (30 loc) · 876 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
32
33
34
import { withAuth } from "next-auth/middleware"
import { NextResponse } from "next/server"
export default withAuth(
function middleware(req) {
// Add any additional middleware logic here
return NextResponse.next()
},
{
callbacks: {
authorized: ({ token, req }) => {
// Protect admin routes
if (req.nextUrl.pathname.startsWith("/admin")) {
return token?.role === "admin"
}
// Protect dashboard and other authenticated routes
if (
req.nextUrl.pathname.startsWith("/dashboard") ||
req.nextUrl.pathname.startsWith("/chat") ||
req.nextUrl.pathname.startsWith("/profile")
) {
return !!token
}
return true
},
},
},
)
export const config = {
matcher: ["/dashboard/:path*", "/chat/:path*", "/profile/:path*", "/admin/:path*"],
}