【问题标题】:Next-Auth: Cannot read property 'Adapter' of undefinedNext-Auth:无法读取未定义的属性“适配器”
【发布时间】:2021-08-02 15:38:32
【问题描述】:

当我在 vercel.in 开发模式下部署 nextjs 应用程序时出现此错误,一切正常,但是当我在 vercel 中部署我的应用程序时出现此错误。

这个错误可能来自下一个身份验证,但我不知道为什么会出现。

我在 [...nextauth].js 中的代码:

export default NextAuth({
session: {
    maxAge: 30 * 24 * 60 * 60,
    jwt: true,
    updateAge: 24 * 60 * 60
},
providers: [
    Providers.Credentials({
        async authorize(credentials) {
            try {
                await dbConnect();

                const findUser = await User.findOne({ email: credentials.email });
                if (!findUser) {
                    throw new Error('User not found.');
                }

                const comparePass = await comparePassword(credentials.password, findUser.password);
                if (!comparePass) {
                    throw new Error('Confirm password not match.');
                }
                return { email: credentials.email, isAdmin: findUser.isAdmin };
            } catch (error) {
                throw new Error(error.message);
            }
        }
    })
]});

当请求 /api/auth/session 和 /api/auth/_log 时会出现此错误

我很高兴有人能帮助我。

【问题讨论】:

    标签: reactjs next.js next-auth


    【解决方案1】:

    您使用的是哪个版本的 next-auth?如果是 3.20.0 及更高版本,则问题与适配器有关。尝试在部署时检查您的函数日志中是否有类似的内容:

    如果是这样,请在将 next-auth 更新到最新版本后尝试卸载 @types/next-auth。它为我解决了这个问题。

    【讨论】:

    • 我使用的是 v3.19,我更新到 v3.23,这解决了我的问题。非常感谢。
    猜你喜欢
    • 2023-01-31
    • 2018-08-31
    • 2020-10-28
    • 2017-09-16
    • 2019-07-28
    • 1970-01-01
    • 2022-07-06
    • 2022-01-15
    • 2020-09-09
    相关资源
    最近更新 更多