小编Gog*_*ogi的帖子

Firebase JS 错误:由于令牌更改,getToken 中止

使用 JavaScript 库运行 Firestore 事务时,我收到 Firebase 错误“错误:由于令牌更改中止getToken” 。错误不会每次都抛出,我找不到模式。我想我已经在某处实施了一些竞争条件。

我的应用程序中的用户流程是这样的:

  1. 注册一个新帐户并以相同的形式提交额外的字符串
  2. 注册后使用相同的凭据登录用户
  3. 登录后,获取该附加字符串并将其保存到 Firestore(在事务中)。
  4. 由于交易失败 Error: getToken aborted due to token change.

承诺流程:

    firebase.auth().createUserWithEmailAndPassword(email, password)
      .catch(signupError => {
        // no problems here
      })
      .then(() => {
        return firebase.auth().signInWithEmailAndPassword(email, password)
      })
      .catch(loginError => {
        // no problem here
      })
      .then((user) => {
        // Database write call which fails (see lower code block)
        return this.claimInput.writeClaimedPlace(user.user.uid, claimedPlace);
      })
      .catch(error => {
        // "getToken aborted" ERROR GETS CAUGHT HERE, transaction fails …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication google-cloud-firestore

6
推荐指数
1
解决办法
2578
查看次数