首页 > 解决方案 > 从同一设备进行第二次注册尝试时未执行 Firestore 写入操作

问题描述

所以我整天都在做这个,我仍然无法弄清楚或在网上找到任何帮助。我很确定这是我想念的非常小的东西。我会尽力解释我的问题。

我有一个带有 Firestore 和 Firebase-Authentication 的 Vue.js SPA。今天我注意到我的应用程序出现了一些奇怪的行为,我认为这与缓存有关。所以我有 SignUp 组件,其中有以下内容:

firebase
    .auth()
    .createUserWithEmailAndPassword(this.email, this.password)
    .then(
      function(user) {
         firebase
          .firestore()
          .collection("users")
          .doc(user.user.uid)
          .set({
            firstname: _this.fName,
            lastname: _this.lName,
            username: _this.uName,
            email: user.user.email
          })
          .then(() => {
            _this.$store.commit('setCurrentUser', {email: user.user.email, uid: user.user.uid})  
            
            _this.$router.replace("/HomeUserPage");
          })
          .catch(function(error) {                
            console.log("Error signing up:", error);
          });
  },
      function(err) {
         console.log(err.message, "this is an error");
      }
    )

我在另一个组件中也有这样的 SignOut 处理程序:

firebase
    .auth()
    .signOut()
    .then(() => {
      this.$router.replace("Login");
    })
    .catch(function(error) {
     console.log(error);
     
    });

我的问题如下:每当我注销并尝试创建一个新用户(注册)时,它第一次就完美了。然后我注销,并尝试再注册一个用户,现在发生的事情是我创建了用户,但是,在 .createUserWithEmailAndPassword 的回调中对 firestore 数据库的调用没有执行,因此,我的路线没有改变而且我的数据没有被填充。

到目前为止我发现了什么:如果我在注销后重新加载页面就不会发生这种情况(因此,为什么我认为问题来自缓存)。

您有什么想法为什么会发生这种情况,这是预期的行为吗?我只是希望在每次注销后重新加载页面?

标签: javascriptfirebasevue.jsgoogle-cloud-firestorefirebase-authentication

解决方案


好吧,我想通了。显然,这是 Doug 上面提到的一个错误,所以我去 Github 上发布它,并且已经报告了它:

https://github.com/firebase/firebase-js-sdk/issues/3218

这是旧版本(7.15)中的一个问题,现在已修复(7.16)。所以刚刚更新了我的 Firebase SDK,现在一切都按预期工作了。


推荐阅读