【问题标题】:Next-Auth getSession is returning null in my development environmentNext-Auth getSession 在我的开发环境中返回 null
【发布时间】:2021-04-30 17:34:01
【问题描述】:

我在我的一个页面中使用了以下代码:

export async function getServerSideProps(context) {
  const session = await getSession(context)
  return {
    props: { session }
  }
}

并且会话返回 null。我收到以下错误:

[next-auth][error][client_fetch_error] [
  'http://localhost:3000/api/auth/session',
  FetchError: request to http://localhost:3000/api/auth/session failed, reason: read ECONNRESET

如果我尝试在浏览器中导航到 http://localhost:3000/api/auth/session,我会正常获取会话对象。另外,我的同事在他的机器上也有相同的代码,而且对他来说运行良好。

我知道我的环境和他的环境之间的唯一区别是我使用的是 windows,而他使用的是 mac。不确定这是否会导致这里出现问题。

【问题讨论】:

  • 你有解决办法吗?

标签: next.js next-auth


【解决方案1】:

而不是这个:

export async function getServerSideProps(context) { ...

像这样将 context 放入 {}:

export async function getServerSideProps({context}) { ...

【讨论】:

    【解决方案2】:

    尝试删除根目录下的.next文件夹,然后重试

    【讨论】:

      猜你喜欢
      • 2022-10-20
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 2022-07-24
      • 1970-01-01
      • 2019-07-03
      • 2021-10-06
      相关资源
      最近更新 更多