【问题标题】:how to run a code after firestore .update() is finished in server in angularfirestore .update() 在服务器中以角度完成后如何运行代码
【发布时间】:2020-05-11 23:15:53
【问题描述】:

我正在尝试发送本地生成的令牌以在用户登录时将其存储在 localstorage 和 firestore 中,然后将用户路由到管理组件,然后在应用程序组件中 订阅用户并比较存储的令牌和localstorage存储的用户,如果它们彼此不同,应用程序将注销用户 但真正的情况是,当本地存储中的令牌更改时,firestore 中的更改需要一些时间,因此订阅通知 2 个令牌(更改前的 firestore 中的旧令牌和存储在本地存储中的新令牌)不同,然后立即注销用户

【问题讨论】:

    标签: angular firebase firebase-realtime-database google-cloud-firestore angular9


    【解决方案1】:

    您可以在 Firestore 中首次更新数据后将令牌写入本地存储:

    db.collection("collection").doc("doc").update(data)
    .then( () => {
        console.log("Document successfully written!");
    
        window.localStorage.setItem( key, token );
    
    })
    .catch(function(error) {
        console.error("Error writing document: ", error);
    });
    

    db、"collection"、"doc"、key、token 仅具有代表性。你应该用你的数据替换。

    希望对您有所帮助!编码愉快!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多