繁体   English   中英

在 angular 的服务器中完成 firestore.update() 后如何运行代码

[英]how to run a code after firestore .update() is finished in server in angular

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

在 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"keytoken只是代表性的。 您应该替换为您的数据。

希望能帮助到你! 编码愉快!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM