first commit
This commit is contained in:
21
proxy.ts
Normal file
21
proxy.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { withAuth } from "next-auth/middleware";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export default withAuth(
|
||||
function middleware(req) {
|
||||
const token = req.nextauth.token;
|
||||
const isAdminRoute = req.nextUrl.pathname.startsWith("/admin");
|
||||
if (isAdminRoute && token?.role !== "ADMIN") {
|
||||
return NextResponse.redirect(new URL("/", req.url));
|
||||
}
|
||||
},
|
||||
{
|
||||
callbacks: {
|
||||
authorized: ({ token }) => !!token,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export const config = {
|
||||
matcher: ["/admin/:path*", "/team/:path*"],
|
||||
};
|
||||
Reference in New Issue
Block a user