I\'m trying to reset the store after logout in my react-apollo application.
So I\'ve created a method called \"logout\" which is called when I click on a button (and pas
client.resetStore() doesn't actually reset the store. It refetches all active queries
Above statement is very correct.
I was also having the logout related problem. After using client.resetStore()
It refetched all pending queries, so if you logout the user and remove session token after logout you will get authentication errors.
I used below approach to solve this problem -
{
sessionStorage.clear()
client.clearStore().then(() => {
client.resetStore();
history.push('/login')
});
}}
>
{logout => (
)}
Important part is this function -
onCompleted={()=> {
sessionStorage.clear(); // or localStorage
client.clearStore().then(() => {
client.resetStore();
history.push('/login') . // redirect user to login page
});
}}