[英]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.