client.resetStore on logout is wrong
See original GitHub issueThe documentation says that you should use client.resetStore()
on logout, but that is wrong. If you do that, then the queries get refetched and cached with User A’s permissions and then when User B logs in, the query is already fetched and cached, so it doesn’t fetch data again, and instead it shows User A’s data to User B because it’s in the cache.
Either a new function called clearStore()
needs to be created or the documentation should be updated to say that localStorage.clear()
(or whatever methodology you’re using to persist data locally’s clear out function).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Reset store after logout with Apollo client
After using client.resetStore() It refetched all pending queries, so if you logout the user and remove session token after logout you will get ......
Read more >clearStore() vs resetStore() - Help
resetStore () after your login or logout process has completed. This will cause the store to be cleared and all active queries to...
Read more >Authentication - Client (React) - Apollo GraphQL Docs
resetStore () after your login or logout process has completed. This will cause the store to be cleared and all active queries to...
Read more >Fullstack part8 | Login and updating the cache
We can reset the cache using the resetStore method of an Apollo client object. The client can be accessed with the useApolloClient hook:....
Read more >[Solved]-Reset store after logout with Apollo client-Reactjs
import { withApollo } from 'react-apollo'; class Layout extends Component { ... logout = () => { this.props.client.resetStore(); alert("YOUHOU"); } .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
also having this issue. Agree that we need a
clearStore()
function, because after logout (removing the auth token) and callingclient.resetStore()
the refetched queries throw errors because the lack of authorization@fenos tried your method didn’t work.
Seeing the same problem here.
Intended: errors resulting from UserA’s queries should be cleared out on client.resetStore()
Actual: User B component props show errors from userA’s queries
Query from User A returns an error in data, as expected.
{ error: { graphQLErrors: [ { Error: <message from User A>} ] } }
However, after client.resetStore, User B still sees:{ error: { graphQLErrors: [ { Error: <message from User A>} ] } }
I dug in deeper and saw that the errorLink from UserB didn’t return any error, so the Error must have been read from cache. Then I console.log the cache from before and after resetStore and found that store data was cleared. Makes no sense. Anyone else has a clue?