question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client.resetStore on logout is wrong

See original GitHub issue

https://github.com/apollographql/apollo-client/blob/master/docs/source/recipes/authentication.md#reset-store-on-logout

The 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:closed
  • Created 6 years ago
  • Reactions:17
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

16reactions
bogdansoarecommented, Feb 8, 2018

also having this issue. Agree that we need a clearStore() function, because after logout (removing the auth token) and calling client.resetStore() the refetched queries throw errors because the lack of authorization

11reactions
blacklakeDevcommented, Jan 9, 2018

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found