简体   繁体   English

无法将未定义或 null 转换为 Next.js 中的 object

[英]Cannot convert undefined or null to object in Next.js

Hey I am building a login page with Next.js and next-auth I have also written in providers array in [...nextauth].js .嘿,我正在使用 Next.js 和 next-auth 构建一个登录页面,我还在[...nextauth].js中的 providers 数组中写入。

But when I run the code (given below):-但是当我运行代码时(如下所示): -

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,
    },
  };
}

I get the我明白了

错误图像

This is the console at compilation这是编译时的控制台

[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'
}

Any help would be appreciated.任何帮助,将不胜感激。 Note: I tried using注意:我尝试使用

From the look of the code you've supplied, providers is assigned only when the asynchronous call getProviders resolves.从您提供的代码的外观来看,只有在异步调用getProviders解析时才会分配提供providers

This means that at runtime providers in Object.values(providers) is undefined .这意味着在运行时Object.values(providers) providers的提供程序是undefined

In Login you can give provide a default until providers is actually available:Login中,您可以提供默认值,直到providers实际可用:
Login({ providers = {} })

Can you post your next.js version as next-auth/react implementation is different based on its version.您能否发布您的next.js版本,因为next-auth/react实现根据其版本而有所不同。

I doubt if there is already another application is running on your localhost with the same port number.我怀疑是否已经有另一个应用程序正在使用相同的端口号在您的本地主机上运行。 Or you are using https instead of http for the next.js dev server.或者,您在next.js开发服务器上使用https而不是http

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Next.js useContext TypeError:无法解构“对象(…)(…)”,因为它未定义 - Next.js useContext TypeError: Cannot destructure 'Object(…)(…)' as it is undefined 无法将未定义或 null 转换为 object js - Cannot convert undefined or null to object js 无法将未定义或null转换为对象 - Cannot convert undefined or null to object React JS:TypeError:无法将未定义或空值转换为对象 - React JS: TypeError: Cannot convert undefined or null to object 未捕获的类型错误:无法将未定义或 null 转换为 object React JS - Uncaught TypeError: Cannot convert undefined or null to object React JS 渲染错误:“TypeError:无法在 vue js 中将未定义或 null 转换为对象”? - Error in render: “TypeError: Cannot convert undefined or null to object” in vue js? Draft.js无法将未定义或null转换为对象convertFromRaw - Draft.js Cannot convert undefined or null to object convertFromRaw Google Cloud Function JS错误:无法将undefined或null转换为object - Google Cloud Function JS Error: Cannot convert undefined or null to object 伴侣-bubble.js:无法将未定义或 null 转换为 object - companion-bubble.js: Cannot convert undefined or null to object Next.js:无法读取未定义的属性(读取“indexOf”) - Next.js: Cannot read properties of undefined (reading 'indexOf')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM