Nuxt 阿波罗认证

问题描述

我尝试使用 nuxt 和 apollo 构建身份验证。 登录注册非常简单,也可以设置 jwt 令牌,但是当我的令牌过期并且我尝试获取刷新令牌或注销我的用户时,我收到以下错误

Invariant Violation
Store reset while query was in flight (not completed in link chain)

由于我在 nuxt.config.js 中定义的错误处理程序不起作用,我尝试构建自己的客户端。

所以我设置了 apollo.clientConfigs.default 我的 ~/graphql/config.ts 看起来像

export default ({ app }: Context) => {
  const errorLink = onError(({ graphQLErrors,networkError,operation,forward }) => {
    if (graphQLErrors) {
      graphQLErrors.map(async (err) => {
        if (err?.extensions?.exception.status === 401) {
          await app.$apolloHelpers.onlogout()
        }

        return err
      })

      return forward(operation)
    }

    if (networkError) {
      console.log(networkError,'and another one!')
      return forward(operation)
    }

    return forward(operation)
  })

  return {
    httpEndpoint: 'http://localhost:3001/graphql',link: from([errorLink as any])
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)