Next-Auth 警告问题
我正在开发 Facebook 克隆代码。 我对 Next.js 很陌生,
它向我抛出一个错误,我不确定它是标准的还是我的代码中的一些错误。
https://next-auth.js.org/warnings#no_secret
[next-auth][warn][NO_SECRET]
谁能解释一下吗?
[...nextauth].js
import NextAuth from "next-auth"
import FacebookProvider from "next-auth/providers/facebook";
export default NextAuth({
// Configure one or more authentication providers
providers: [
FacebookProvider({
clientId: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET
})
]
})
import '../styles/globals.css'
import {SessionProvider} from "next-auth/react"
function MyApp({ Component, pageProps }) {
return (
<SessionProvider>
<Component {...pageProps} />
</SessionProvider>
)}
export default MyApp
FACEBOOK_CLIENT_ID=495472355295570
FACEBOOK_CLIENT_SECRET=secret is from facebook for developers
NEXTAUTH_URL=http://localhost:3000```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NEXTAUTH_URL 是您网站的规范 URL。
对于开发,NEXTAUTH_URL 类似于
NEXTAUTH_URL=http://localhost:3000/
对于生产,NEXTAUTH_URL 类似于
NEXTAUTH_URL=http://officialrajdeepsingh.dev
了解有关 NEXTAUTH_URL 详细信息的更多信息文档数量
https://next-auth.js.org/configuration/options
NEXTAUTH_URL is the canonical URL of your site.
for development, NEXTAUTH_URL looks like
NEXTAUTH_URL=http://localhost:3000/
for production, NEXTAUTH_URL looks like
NEXTAUTH_URL=http://officialrajdeepsingh.dev
Read more about NEXTAUTH_URL details of docs
https://next-auth.js.org/configuration/options
对于您的生产阶段,例如,假设您正在 Vercel 上进行部署。
您需要应用程序的密钥。
进一步阅读。 缺少什么秘密 和 什么是秘密
要修复:
您需要应用程序的秘密,可以通过以下方式生成这来自 varcel
生成您在 .env.local 中设置 NEXTAUTH_SECRET ,例如
NEXTAUTH_SECRET=af017d04a8083251abdebb81b1fbb498
您将机密添加到文件 [...nextauth].js 中,如下所示(process. env.NEXTAUTH_SECRET),因为您不想公开密钥。
<代码>...
导出默认NextAuth({
<代码> ...
提供商:[...],
秘密:process.env.NEXTAUTH_SECRET,
<代码> ...
<代码>})
您在 vercel 项目中添加您的密钥 像这样。
就这样,问题应该消失了。除非您部署在其他平台上,否则配置可能会有所不同。
For your production phase, e.g. let's say your're deploying on Vercel.
You need your app's secret key.
Further readings. what is missings secret and what is secret
To fix:
You need your application's secret which can be generated via this like by varcel
You set NEXTAUTH_SECRET in your .env.local like
NEXTAUTH_SECRET=af017d04a8083251abdebb81b1fbb498
You add your secret to the file [...nextauth].js like this(process.env.NEXTAUTH_SECRET) because you don't want to expose the key.
...
export default NextAuth({
...
providers: [...],
secret: process.env.NEXTAUTH_SECRET,
...
})
You add your secret on your vercel project like this.
That's all, the problem should be gone. Unless you deploy on other platform, the configuration might be different.
试试这个:
只需添加秘密就可以了
Try this:
Just add the secret and it should be ok