【问题标题】:Cannot convert undefined or null to object in Next.js无法在 Next.js 中将 undefined 或 null 转换为对象
【发布时间】:2022-01-24 12:06:23
【问题描述】:

嘿,我正在使用 Next.js 和 next-auth 构建登录页面 我还在 [...nextauth].js 的 providers 数组中写了。

但是当我运行代码时(如下所示):-

import { getProviders, signIn } from "next-auth/react";

function Login({ providers }) {
  return (
    <div>
      <img src="/spot-it-aye.png" alt="" />

      {Object.values(providers).map((provider) => (
        <div key={provider.name}>
          <button
            onClick={() => signIn(provider.id, { callbackUrl: "/" })}>
            Login With {provider.name}
          </button>
        </div>
      ))}
    </div>
  );
}

export default Login;

export async function getServerSideProps() {
  let providers = await getProviders();

  return {
    props: {
      providers,
    },
  };
}

我明白了

这是编译时的控制台

[next-auth][error][CLIENT_FETCH_ERROR] 
https://next-auth.js.org/errors#client_fetch_error request to https://localhost:3000/api/auth/providers failed, reason: write 
EPROTO 12752:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
 {
  error: {
    message: 'request to https://localhost:3000/api/auth/providers failed, reason: write EPROTO 12752:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:\n',
    stack: 'FetchError: request to https://localhost:3000/api/auth/providers failed, reason: write EPROTO 12752:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:\n' +       
      '\n' +
      '    at ClientRequest.<anonymous> (E:\\Coding\\VSCode\\Next JS\\spotify-2.0\\node_modules\\node-fetch\\lib\\index.js:1461:11)\n' +
      '    at ClientRequest.emit (node:events:390:28)\n' +
      '    at ClientRequest.emit (node:domain:475:12)\n' +
      '    at TLSSocket.socketErrorListener (node:_http_client:447:9)\n' +
      '    at TLSSocket.emit (node:events:390:28)\n' +
      '    at TLSSocket.emit (node:domain:475:12)\n' +
      '    at emitErrorNT (node:internal/streams/destroy:157:8)\n' +
      '    at emitErrorCloseNT (node:internal/streams/destroy:122:3)\n' +
      '    at processTicksAndRejections (node:internal/process/task_queues:83:21)',
    name: 'FetchError'
  },
  path: 'providers',
  message: 'request to https://localhost:3000/api/auth/providers failed, reason: write EPROTO 12752:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:\n'
}

任何帮助将不胜感激。 注意:我尝试使用

【问题讨论】:

标签: javascript reactjs next.js next-auth


【解决方案1】:

您能否发布您的next.js 版本,因为next-auth/react 的实现因版本而异。

我怀疑是否已经有另一个应用程序在您的本地主机上运行具有相同的端口号。或者,您使用 https 而不是 http 作为 next.js 开发服务器。

【讨论】:

  • 这应该作为评论而不是作为答案添加。答案严格用于解决 OP 的问题。
猜你喜欢
  • 2022-10-24
  • 1970-01-01
  • 1970-01-01
  • 2021-07-29
  • 2020-07-19
  • 2020-12-06
  • 1970-01-01
  • 1970-01-01
  • 2022-06-22
相关资源
最近更新 更多