next.js JSON中的位置0'下一个验证的意外标记S

ix0qys7i  于 2023-05-06  发布在  其他
关注(0)|答案(3)|浏览(134)

我和一个队友正在开发一个应用程序门户。我们有相同的代码、节点版本和环境变量,但当他登录时,他得到了这个错误。我能够登录完美没有任何错误。他上周也能登录,所以有一次这对他很有效。
我读到的很多解决方案都是添加代码来修剪或简化JSON响应。但这是没有意义的,它为我工作,因为它是,但他将需要添加代码,使他的工作。有人知道为什么会这样吗?(他在.env中也有一个NEXTAUTH_URL)。

[next-auth][error][CLIENT_FETCH_ERROR] 
https://next-auth.js.org/errors#client_fetch_error invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0 {
  error: {
    message: 'invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0',
    stack: 'FetchError: invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0\n'
a6b3iqyw

a6b3iqyw1#

我在next-redux-wrapper中遇到了同样的错误。我正在执行旧版本的设置。我有这个导致错误:

export const getServerSideProps = wrapper.getServerSideProps(
  async ({ req, params, store }) => {
    const session = await getSession({ req });

    if (!session) {
      return {
        redirect: {
          destination: "/login",
          permanent: false,
        },
      };
    }

    await store.dispatch(getBookingDetails(req.headers.cookie, req, params.id));
  }
);

我不得不把它改成:

// the way how I pass callback changed
export const getServerSideProps = wrapper.getServerSideProps(
  (store) =>
    async ({ req, params }) => {
      ....rest of the code
);
6ioyuze2

6ioyuze22#

电子邮件提供商似乎发生了一些事情。
我得到了同样的错误,但当我看我的localhost节点控制台的东西,它说,它找不到模块“nodemailer”所以我删除了电子邮件提供商的导入,它停止了。
这个东西”import EmailProvider from 'next-auth/providers/email'“
我想可能是他们缺少那个模块而你没有。
这并不是说这会有很大帮助,但可能是其中的一个线索:P

4ktjp1zp

4ktjp1zp3#

我最近遇到了同样的问题,但幸运的是,我设法解决了它。
解决方案是:(1).env中需要NEXT_PUBLIC_SECRET,(2)[...nextauth].ts加上secret:process.env.NEXT_PUBLIC_SECRET
我要感谢the following link提供上述解决方案。
希望它也能为你工作。

相关问题