initial commit - code moved to separate repo
This commit is contained in:
41
middleware.ts
Normal file
41
middleware.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { withAuth } from "next-auth/middleware";
|
||||
|
||||
import { UserRole } from "@prisma/client";
|
||||
|
||||
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
|
||||
export default withAuth({
|
||||
callbacks: {
|
||||
authorized({ req, token }) {
|
||||
console.log("req", req);
|
||||
// `/admin` requires admin role
|
||||
if (req.nextUrl.pathname === "/examples/admin") {
|
||||
return token?.userRole === "adminer"
|
||||
}
|
||||
|
||||
if (req.nextUrl.pathname === "/cart" && token?.role === UserRole.ADMIN) {
|
||||
// return NextResponse.redirect(new URL("/", req.url));
|
||||
return true;
|
||||
}
|
||||
// if(req.nextUrl.pathname === "/cart"){
|
||||
// return token?.role !== Role.ADMIN;
|
||||
// }
|
||||
|
||||
|
||||
// `/me` only requires the user to be logged in
|
||||
return !!token
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const config = {
|
||||
// matcher: ["/admin", "/me"]
|
||||
matcher: ["/admin/:path*", "/me", "/cart, /"],
|
||||
// callbackUrl: {
|
||||
// name: `__Secure-next-auth.callback-url`,
|
||||
// options: {
|
||||
// sameSite: 'lax',
|
||||
// path: '/',
|
||||
// secure: true
|
||||
// }
|
||||
// },
|
||||
}
|
Reference in New Issue
Block a user