我在Vercel上的Preview部署中不断收到此错误消息:
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error Unexpected token < in JSON at position 0 {
error: {
message: 'Unexpected token < in JSON at position 0',
stack: 'SyntaxError: Unexpected token < in JSON at position 0\n' +
' at JSON.parse (<anonymous>)\n' +
' at parseJSONFromBytes (node:internal/deps/undici/undici:6498:19)\n' +
' at successSteps (node:internal/deps/undici/undici:6472:27)\n' +
' at node:internal/deps/undici/undici:1145:60\n' +
' at node:internal/process/task_queues:140:7\n' +
' at AsyncResource.runInAsyncScope (node:async_hooks:204:9)\n' +
' at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
name: 'SyntaxError'
},
url: 'https://[my-censored-domain-name].com/api/auth/providers',
message: 'Unexpected token < in JSON at position 0'
}
JSON是:
{
"google":{
"id":"google",
"name":"Google",
"type":"oauth",
"signinUrl":"https://[my-censored-domain-name].com/api/auth/signin/google",
"callbackUrl":"https://[my-censored-domain-name].com/api/auth/callback/google"
},
"email":{
"id":"email",
"name":"Email",
"type":"email",
"signinUrl":"https://[my-censored-domain-name].com/api/auth/signin/email",
"callbackUrl":"https://[my-censored-domain-name].com/api/auth/callback/email"
}
}
以下是我尝试过的:
- 将
NEXTAUTH_URL
设置为我的自定义域名(不是vercel域名) - 设置
NEXTAUTH_SECRET
- 使用
NEXTAUTH_SECRET
将secret
添加到[...next-auth].ts
- 临时添加
NEXTAUTH_INTERNAL_URL = http://localhost:8080
到我的环境配置 - 在
signIn()
调用之前添加了e.preventDefault()
有人能帮我吗?next-auth
文档说要设置NEXTAUTH_URL
,但它显然是在Vercel上设置的。
1条答案
按热度按时间wmomyfyw1#
我发现了这个问题,多亏了这个GitHub评论。
如果您的Next Auth配置正确,则应禁用Vercel上的“Deployment Protections”。您可能需要清除您的Cookie。