mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* merge `main`, fix workspace dependencies * chore(dev): use `matcher` in Middleware * fix(middleware): support `cookies` as `Map` * simplify * chore(example): use new Middleware API * chore(example): use `next-auth@latest` * docs(middleware): document new Middleware API * docs(ts): update inline example * fix(ts): make cookies optional * remove non-null assertion
13 lines
447 B
TypeScript
13 lines
447 B
TypeScript
import { withAuth } from "next-auth/middleware"
|
|
|
|
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
|
|
export default withAuth({
|
|
callbacks: {
|
|
authorized: ({ req, token }) =>
|
|
// /admin requires admin role, but /me only requires the user to be logged in.
|
|
req.nextUrl.pathname !== "/admin" || token?.userRole === "admin",
|
|
},
|
|
})
|
|
|
|
export const config = { matcher: ["/admin", "/me"] }
|