Skip to content

Commit b7065a6

Browse files
committed
chore: correct Middleware logic in Next.js example
1 parent 61b92ec commit b7065a6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

apps/example-nextjs/middleware.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { withAuth } from "next-auth/middleware"
33
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
44
export default withAuth({
55
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",
6+
authorized({ req, token }) {
7+
// `/admin` requires admin role
8+
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+
},
914
},
1015
})
1116

0 commit comments

Comments
 (0)