javascript - Firestore 如何清除Persistence()
问题描述
用户注销后,我需要完全清除当前用户数据。因此我使用 clearPersistence() 函数。它需要在 clearPersistence() 之前运行 terminate()。
this.afs.firestore.terminate().then(() => {
this.afs.firestore.clearPersistence().then(() => {
});
});
在上面运行以清除 Firestore 本地缓存后,我收到此错误。
FirebaseError: The client has already been terminated.
任何建议如何重新初始化 Firestore 实例或任何更好的方法来实现?谢谢。
解决方案
这不是clearPersistence()
. 我建议仔细阅读API 文档:
必须在 firestore 实例未启动时调用(应用程序关闭后或应用程序首次初始化时)。在启动时,这个方法必须在其他方法(除了 settings())之前调用。如果 firestore 实例仍在运行,promise 将被拒绝,错误代码为 failed-precondition。
注意:clearPersistence() 主要用于帮助编写使用 Cloud Firestore 的可靠测试。它使用一种有效的机制来删除现有数据,但不会尝试安全地覆盖或以其他方式使缓存数据不可恢复。对于对用户会话之间的缓存数据泄露敏感的应用程序,我们强烈建议根本不启用持久性。
第二段告诉您,您可能根本不应该启用持久性。
第一段告诉您,在测试期间使用 clearPersistence 只能在 Firestore 应用程序实例首次初始化后(并且在任何查询之前)或应用程序完全关闭后立即完成。
推荐阅读
- powershell - 获取唯一值
- python - 函数的多个输入,特别是 itertools.product()
- swift - 在 tvOS 12 的 TVUIKit 中使用 TVPosterImage
- ubuntu - ssh key gitlab CI .gitlab-CI.yml 设置失败
- ios - 如何将我的网络代码与我的 ViewController 分开
- c#-4.0 - 以编程方式重置具有无效数据的日期时间字段
- css - 在 Firefox 中隐藏滚动条
- css - 包含 bootstrap 4 样式表时,Flex 增长动画不起作用
- tsql - 使用 Print() 打印超过 8000 个字符
- angular - 使用 Nativescript 更改颜色和图标菜单