I am trying to add a middleware in the route /admin at next.js, and in the file " _middleware.js" it is like this:
import { withAuth } from "next-auth/middleware";
export default withAuth({
callbacks: {
authorized({ req, token }) {
if (token) return true; // If there is a token, the user is authenticated
},
},
});
Error:
./pages/admin/_middleware.js:1:0
Module not found: Package path ./middleware is not exported from package
Path:
pages
|-------admin
|--------------_middleware.js
|--------------index.js
The solution, update your nextAuth dependence. withAuth was an update at 4.2.0. https://github.com/nextauthjs/next-auth/releases/tag/v4.2.0 Special thanks to juliomalves