I'm working on an Expo React Native app that uses Redux Toolkit and RTK Query. We recently created some extra test accounts so that we could simulate user permissions, and we started running into issues where after logging out from Account 1
and logging in to Account 2
, requests still seemed to be made with Account 1
's tokens.
My initial assumption was that the Redux store was leaking state between user sessions, so I installed React Native Debugger. I verified that state management was working correctly, and enabled "Network Inspect" to take a look at the requests. Suddenly, everything began working as expected. I could switch between Account 1
and Account 2
repeatedly, and the RTK Query requests would return the correct data every time.
I've found some similar questions, but none of them have helped in this case:
I would really appreciate any help with this. It's driving me mad, and I spent hours trying to fix it today before I discovered this quirk with the debugger. Apologies for not including any code; given the nature of the problem, I'm really not sure which parts of the codebase (if any) would be useful. Thank you!
We ended up solving this. It turns out that requests were being cached at the system level, outside of our app. React Native Debugger does not cache requests, which explains the behavior we observed.
Adding a Cache-Control
header to the problem requests, with a value of either no-cache
or no-store
, fixed the problem.