RTK query seems to work so that when cached results get invalidated, the invalidated query is being re-fetched immediately. I would expect that a re-fetch would execute when the program requests invalidated data, but not sooner.
Real world use case
Suppose I have an app where the user needs to login - so something that majority of webapps do. Let's say I have three endpoints:
- login mutation - logs the user in
- getAuthInfo query - gets the authenticated session data (has
providesTags: ['AuthData']
set) - logout mutation - logs the user out (has
invalidatesTags: ['AuthData']
set)
When the user logs in, the code requests authenticated session info. And this data naturally gets cached as many pages may need certain data of this information.
But when the user later logs out, the cached data gets invalidated (as per auto-invalidation tags settings), and gets therefore immediately re-fetched by the RTK query lib. Such a call fails with HTTP 401 for obvious reasons.
Question
How can I prevent an invalidated query from being immediately re-fetched? In the upper example I would want data to be re-fetched when the code makes a new call to the endpoint but not sooner. Is it possible to control re-fetching behaviour in RTK Query?