StreamProvider releasing all of streams over the whole app #1134
Replies: 2 comments 1 reply
-
You could make a separate provider that watches whether the user is logged in or not. Then within the providers listening to collection snapshots, watch this new provider. This way when the user logs out, the collection snapshot providers will refresh. |
Beta Was this translation helpful? Give feedback.
-
Aggreed, that looks like a solution. But there are following problems to that:
I'm not sure if the 2. point could happen. What do you think? Also a problem with this approach is that I could forget to add that logic into every relevant provider 🤔 |
Beta Was this translation helpful? Give feedback.
-
I encountered this challenge at multiple projects overall.
Imagine using snapshots with Firebase (streaming changes).
In case there are security rules that a user can listen to this entity only when logged in, then in case of logout all these streams finish with error. And in case I have error logging in the app, I don't want to log errors over the whole app when a user logs out 😄
I wonder if there is any available mechanism with riverpod to solve this artifact?
I'm thinking about any possibility to close all streams that
StreamProvider
s hold.I think there is some container with all the available providers (
ProviderScope
), maybe there is a possibility to iterate over all the providers check if it is aStreamProvider
and close it somehow?What is a nice approach to solve this problem? Does riverpod provide any clean solution?
Beta Was this translation helpful? Give feedback.
All reactions