【发布时间】:2022-02-06 16:16:29
【问题描述】:
我正在尝试在 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
【问题讨论】:
-
如果您没有在代码中使用
withAuth,为什么还要尝试导入它? -
您使用的是哪个版本的
next-auth?withAuth是在 v4.2.0 中引入的。 -
@tromgy 我正在使用,如果我不导入它会导致错误。
-
@juliomalves "next-auth": "^4.1.2",我该如何更新
-
@juliomalves 在 _middleware.js,令牌为 NULL,我在会话中
标签: reactjs next.js middleware next-auth