阿波罗客户的突变

发布于 2025-01-30 19:50:24 字数 472 浏览 3 评论 0原文

我正在使用Apollo客户端执行具有刷新令牌的自动登录。我使用的代码是:

 const expirationTime = exp * 1000 - 60000;
if (Date.now() >= expirationTime) {
  await client //this is how user relogin
  .mutate({
    mutation: USER_LOGIN,
    variables: { rt: localStorage.getItem("refreshToken") },
  })
  .then((response) => console.log(response.data))
  .catch((err) => console.error(err));
}

但是我不确定这是否是正确的方法,因为当我这样做时,我的应用似乎会崩溃。我阅读了React的文档,但除了Usemuont之外找不到其他任何内容

I am using apollo client to perform an auto login with refresh token. The code I use is:

 const expirationTime = exp * 1000 - 60000;
if (Date.now() >= expirationTime) {
  await client //this is how user relogin
  .mutate({
    mutation: USER_LOGIN,
    variables: { rt: localStorage.getItem("refreshToken") },
  })
  .then((response) => console.log(response.data))
  .catch((err) => console.error(err));
}

But I am not sure whether this is the right way, because my app seems to crash when I do this. I read the documentation for react but couldn't find anything other than useMutation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文