flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[cloud_firestore]: Firestore Termination Issue on Flutter Web: "The client has already been terminated" Error After Clearing Persistence

Open sAtluna opened this issue 1 month ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Which plugins are affected?

cloud_firestore

Which platforms are affected?

Web

Description

I am using await FirebaseFirestore.instance.clearPersistence(); to clear cached data after a user signs out.

According to the documentation, this should only be called after terminating the Firestore session.

However, when I attempt to retrieve data again after logging back in, I encounter the following error:

"The client has already been terminated"

Note: This issue only occurs on Flutter Web. It works fine on Flutter mobile.

Are there any steps, which I'm missing? I already tried to recreate the whole Firebase app, but same error.

await FirebaseFirestore.instance.terminate();
await FirebaseFirestore.instance.clearPersistence();

Reproducing the issue

To reproduce the issue where clearing the cached data after a user signs out causes an error on Flutter Web, follow these steps:

After Sign Out of User: Call the following code to clear the cached data:

await FirebaseFirestore.instance.terminate();
await FirebaseFirestore.instance.clearPersistence();

Sign In User: Attempt to sign the user back in.

Retrieve Data: Try to retrieve data from Firestore. For example:

var data = await FirebaseFirestore.instance.collection('your_collection').get();

Encounter Error: Observe the following error message:

"FirebaseError: The client has already been terminated."

Note: This issue only occurs on Flutter Web. On Flutter mobile, it works as expected.

Firebase Core version

2.31.1

Flutter Version

3.19.6

Relevant Log Output

FirebaseError: The client has already been terminated.

Flutter dependencies

Expand Flutter dependencies snippet

Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

sAtluna avatar May 27 '24 08:05 sAtluna