Firestore 如何清除 Persistence()

Firestore how to clearPersistence()

我需要在用户注销后彻底清除当前用户数据。 因此我使用 clearPersistence() 函数。 它需要 运行 在 clearPersistence() 之前终止 ()。

 this.afs.firestore.terminate().then(() => {
      this.afs.firestore.clearPersistence().then(() => {
      });
});

在上面 运行 清除 firestore 本地缓存后,我收到此错误。

FirebaseError: The client has already been terminated.

关于如何重新初始化 firestore 实例的任何建议或任何更好的实现方法? 谢谢

这不是 clearPersistence() 的预期目的。我建议仔细阅读API documentation

Must be called while the firestore instance is not started (after the app is shutdown or when the app is first initialized). On startup, this method must be called before other methods (other than settings()). If the firestore instance is still running, the promise will be rejected with the error code of failed-precondition.

Note: clearPersistence() is primarily intended to help write reliable tests that use Cloud Firestore. It uses an efficient mechanism for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cached data in between user sessions, we strongly recommend not enabling persistence at all.

第二段告诉您,您可能根本不应该启用持久性。

第一段告诉您,在测试期间使用 clearPersistence 只能在 Firestore 应用程序实例首次初始化后(以及任何查询之前)或应用程序完全关闭后立即执行。