mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* chore: dev -> dev/nextjs * chore: move to /examples * chore: move to playgrounds, add dev/sveltekit * Update sync.yml * chore: dev scripts
18 lines
505 B
TypeScript
18 lines
505 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
|
|
if (req.nextUrl.pathname === "/admin") {
|
|
return token?.userRole === "admin"
|
|
}
|
|
// `/me` only requires the user to be logged in
|
|
return !!token
|
|
},
|
|
},
|
|
})
|
|
|
|
export const config = { matcher: ["/admin", "/me"] }
|