next.js 下一个-Auth & Vercel:[ CLIENT_FETCH_ERROR ]:语法错误:JSON中位置0处的意外标记< API/auth/providers

s4chpxco  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(159)

我在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_SECRETsecret添加到[...next-auth].ts
  • 临时添加NEXTAUTH_INTERNAL_URL = http://localhost:8080到我的环境配置
  • signIn()调用之前添加了e.preventDefault()

有人能帮我吗?next-auth文档说要设置NEXTAUTH_URL,但它显然是在Vercel上设置的。

wmomyfyw

wmomyfyw1#

我发现了这个问题,多亏了这个GitHub评论。
如果您的Next Auth配置正确,则应禁用Vercel上的“Deployment Protections”。您可能需要清除您的Cookie。

相关问题