javascript - Next-auth logIn() 在使用 Credentials provider 时卡在/api/auth/providers

标签 javascript next.js frontend next-auth

Next-auth logIn() 无休止地停留在/api/auth/providers 上,可以看出 here .

async authorize(credentials) 部分似乎根本没有执行,因为 console.log 似乎都没有工作

/pages/api/auth/[...nextauth].js

import Providers from 'next-auth/providers';
import connectDB from '../../../lib/connectDB';
import User from '../../../models/User';

export default NextAuth({
    //Configure JWT
    session: {
        jwt: true,
    },
    //Specify Provider
    providers: [
        Providers.Credentials({
            async authorize(credentials) {
                console.log('====THIS MESSAGE IS NOT SHOWN ON CONSOLE====')
                connectDB();
                const user = await User.findOne({
                    email: credentials.email,
                });

                console.log(user);

                if (user & (await user.matchPassword(credentials.passowrd))) {
                    client.close();
                    return { email: user.email };
                }
                client.close();
                return null;
            },
        }),
    ],
});

客户端

  const onLogin = async (values) => {
        const status = await signIn('credentials', {
            redirect: false,
            email: values.email,
            password: values.password,
        });
        console.log('Login Status: ', status);
        // This is not logged as well, due to /api/auth/providers being stuck
  }

最佳答案

难道你没有在 [...nextauth].js 中定义凭据提供程序设置中的字段?

https://next-auth.js.org/v3/configuration/providers#how-to-2

enter image description here

关于javascript - Next-auth logIn() 在使用 Credentials provider 时卡在/api/auth/providers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68885410/

相关文章:

javascript - 如何使用 NestJS 为特定模块添加路由前缀?

javascript - 在 Node.js 中重新定义 "Object"关键字

azure - 如何使用 "Output File Tracing"功能将 NextJs (SSR) 部署到 Azure 应用服务?

css - Wordpress - 更新页面后自定义 css 将不起作用

css - Materialise CSS 导航栏搜索已损坏

javascript - jQuery追加多个div

javascript - 样式化组件未包装另一个样式化组件

next.js - 我可以在 AWS lambda edge 上托管我的 next.js 并拥有单独的 API 服务器吗?

reactjs - 避免在页面文件夹内创建页面

php - 在检查元素 magento 中显示 css 文件