Skip to content

Commit bd7887b

Browse files
authored
feat: Update next-auth middleware (#1432)
* feat: update next-auth, and move to root level middleware * chore: use example middleware
1 parent 384dfa7 commit bd7887b

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

demos/next-auth/middleware.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { withAuth } from "next-auth/middleware"
2+
3+
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
4+
export default withAuth({
5+
callbacks: {
6+
authorized: ({ req, token }) =>
7+
// /admin requires admin role, but /me only requires the user to be logged in.
8+
req.nextUrl.pathname !== "/admin" || token?.userRole === "admin",
9+
},
10+
})
11+
12+
export const config = { matcher: ["/admin", "/me"] }

demos/next-auth/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/next-auth/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
],
2424
"license": "ISC",
2525
"dependencies": {
26-
"next": "^12.1.6",
27-
"next-auth": "^4.3.3",
26+
"next": "^12.2.0",
27+
"next-auth": "^4.7.0",
2828
"nodemailer": "^6.6.3",
2929
"react": "^17.0.2",
3030
"react-dom": "^17.0.2"

demos/next-auth/pages/admin/_middleware.ts

-8
This file was deleted.

demos/next-auth/pages/me/_middleware.ts

-2
This file was deleted.

0 commit comments

Comments
 (0)