withAuth 模块未在 Next.js 的 next-auth 中导出
withAuth module not exported in next-auth in Next.js
我正在尝试在 next.js 的路由 /admin 中添加一个中间件,在文件“_middleware.js”中它是这样的:
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
},
},
});
错误:
./pages/admin/_middleware.js:1:0
Module not found: Package path ./middleware is not exported from package
路径:
pages
|-------admin
|--------------_middleware.js
|--------------index.js
解决办法,更新你的nextAuth依赖。
withAuth 是 4.2.0 的更新。
https://github.com/nextauthjs/next-auth/releases/tag/v4.2.0
特别感谢juliomalves
我正在尝试在 next.js 的路由 /admin 中添加一个中间件,在文件“_middleware.js”中它是这样的:
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
},
},
});
错误:
./pages/admin/_middleware.js:1:0
Module not found: Package path ./middleware is not exported from package
路径:
pages
|-------admin
|--------------_middleware.js
|--------------index.js
解决办法,更新你的nextAuth依赖。 withAuth 是 4.2.0 的更新。 https://github.com/nextauthjs/next-auth/releases/tag/v4.2.0 特别感谢juliomalves