How to rebuild other provider state based on authentication state with generated providers #3395
Replies: 1 comment
-
The annotation is only required for riverpod to function correctly when you use provider in a providerscope (with overrides) that is not the root providerscope. This is called a scoped provider. Maybe you are looking for final authState = await ref.watch(authenticationControllerProvider.future);
return performAsyncCall(const SomeParameters()); This handles error and loading state automatically during |
Beta Was this translation helpful? Give feedback.
-
I got a use case in an app where we provide Guest login (anonymous basically) and Profile login.
Guest login is done through app bootstrap, so each user that would start the app would have an authState.
Profile login is done through classic/social login.
Once a guest logs in, I would need to update a bunch of providers to reevaluate their state. Same when a logged in user (profile) would disconnect.
We are using riverpod generator, so its not that easy to watch a provider as I don't have the hand on it.
Idea of what I think I could do in the build method as I have no where else in generated.
I know there is the dependencies properties fo the @Riverpod annotation, butg it doesn't really cover my needs, unless I'm mistaken but it is just there to ensure providers tree is more robust not to flag a dependency that would trigger a rebuild. I need some clarification on what this annotation should be used for https://github.com/rrousselGit/riverpod/tree/master/packages/riverpod_lint#provider_dependencies-riverpod_generator-only
@rrousselGit gave some insight here #676 (comment) but as I said, I'm using generator so I can't exactly do that.
Plus, given the fact that usually we use
AsyncValue
, doing what has been said in this mentionned issue can be a real probleme as watch would trigger a rebuild for EVERY state of the watched provider (loading, error etc ...), what you would probably want to avoid, and in my case that's what I want. I don't need to do an api call if my auth state is already in error.Maybe some of you might have some better insight ? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions