We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61b92ec commit b7065a6Copy full SHA for b7065a6
apps/example-nextjs/middleware.ts
@@ -3,9 +3,14 @@ import { withAuth } from "next-auth/middleware"
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",
+ authorized({ req, token }) {
+ // `/admin` requires admin role
+ if (req.nextUrl.pathname === "/admin") {
9
+ return token?.userRole === "admin"
10
+ }
11
+ // `/me` only requires the user to be logged in
12
+ return !!token
13
+ },
14
},
15
})
16
0 commit comments