Riverpod AsyncNotifier re-fetches API after logout and causes 401 #4450
Unanswered
akhil-ge0rge
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm very new to Riverpod and I'm implementing a login/logout flow using AsyncNotifier.
I fetch the user profile after login and show the username on the home screen.
The issue is:
When I logout, the profileDetailsProvider automatically rebuilds and calls the profile API again, which returns 401 because tokens are cleared.
I want to stop this API call after logout.
ProfileDetailsProvider
Logout Widget
App Bar
AuthStateProvider
LoginController
Dio Interceptor
Session Controller
Router
Problem
When I log out:
profileDetailsProvider, Riverpod rebuilds it immediately
So the profile is fetched even after logout, which I want to avoid.
and Instead of
calling ref.invalidate(profileDetailsProvider);inlogout, try calling thecleanmethod, which will look like this:After making this change, the logout works without calling the API, but when I log in again, the API doesn’t get called.
Beta Was this translation helpful? Give feedback.
All reactions