Skip to content

Commit

Permalink
chore: correct Middleware logic in Next.js example
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Jul 19, 2022
1 parent 61b92ec commit b7065a6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/example-nextjs/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ 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",
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
},
},
})

Expand Down

0 comments on commit b7065a6

Please sign in to comment.