【问题标题】:withAuth module not exported in next-auth in Next.js在 Next.js 的 next-auth 中未导出 withAuth 模块
【发布时间】: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-authwithAuth 是在 v4.2.0 中引入的。
  • @tromgy 我正在使用,如果我不导入它会导致错误。
  • @juliomalves "next-auth": "^4.1.2",我该如何更新
  • @juliomalves 在 _middleware.js,令牌为 NULL,我在会话中

标签: reactjs next.js middleware next-auth


【解决方案1】:

解决方案,更新您的 nextAuth 依赖项。 withAuth 是 4.2.0 的更新。 https://github.com/nextauthjs/next-auth/releases/tag/v4.2.0 特别感谢juliomalves

【讨论】:

    猜你喜欢
    • 2022-07-10
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 2021-12-04
    • 2022-11-13
    • 2021-08-06
    相关资源
    最近更新 更多