cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

Collection streams are caching older data #118

Closed RA341 closed 1 year ago

RA341 commented 1 year ago

In the log below I am deleting a document from the collection but the deleted data is returned with the stream

flutter: ┌───────────────────────────────────────────────────────────────────────────────
flutter: │ 2
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 👾 firebase listening
flutter: └───────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────
flutter: │ 👾 [
flutter: │ 👾   360214366888013,
flutter: │ 👾   377254055474374
flutter: │ 👾 ]
flutter: └───────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────
flutter: │ 360214366888013
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 👾 deleted from remote
flutter: └───────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────
flutter: │ 2
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
flutter: │ 👾 firebase listening
flutter: └───────────────────────────────────────────────────────────────────────────────
flutter: ┌───────────────────────────────────────────────────────────────────────────────
flutter: │ 👾 [
flutter: │ 👾   360214366888013,
flutter: │ 👾   377254055474374
flutter: │ 👾 ]
flutter: └───────────────────────────────────────────────────────────────────────────────

my code for reference

Stream<List<Passwords>> fetchAllData() =>
      getDataCollection.stream.map((docs) => docs.map(decryptForLocal).toList());

I am not sure if this is a issue with firestore or firedart, any help is appreciated !

cachapa commented 1 year ago

Thanks for the report.

Fyi: I'm not actively maintaining this package due to lack of time, but I'm accepting contributions in case you want to dive into this problem yourself.

Otherwise it would be great if you could post a minimal code that reproduces the problem. A good candidate is to take the example code and change it so it triggers the problem.

RA341 commented 1 year ago

So I did some poking around and turns out I had stupid firebase rule that somehow worked for creating, reading, etc, but it was not allowing the stream to be updated, so I removed it and its working now.

Marking it as closed now. My bad

My rule that was causing issue

service cloud.firestore {
   match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}

What fixed it

service cloud.firestore {
   match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth != null ;
    }
  }
}