-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client.resetStore on logout is wrong #2774
Comments
to me the doc sounds correct. What about using this flow so that you'll always get consistent cache for your logged in / out users?
Then if the flow repeats for From what I'm aware |
@fenos tried your method didn't work. Seeing the same problem here. Intended: Actual: Query from User A returns an error in data, as expected. |
here are the versions |
~~@blacklakeDev I have not updated to apollo-client 2 yet. The Cache has a Edit: Not related to your actual issue. |
@blacklakeDev I created this example: https://codesandbox.io/s/61o2xxmn0w
Edit: I was able to reproduced this issue in the sandbox! You should change the issue title since it is misleading. Edit: This issue could be related to #2513 |
also having this issue. |
If you have active queries that require authorization after logout, that just means you need to redirect the user to a page without privileged queries before logout. The queries are just doing what they are supposed to do. What you can do, however, is intercept queries that result in a permission error, and if the user is logged out, prompt them to log in again. That way you can have an SPA that is running longer than the session time, and the user can log in again without losing app state. |
Also what about subscription ? When you do resetStore it doesn't destroy Websocket connection instead i should do something like this.webSocketLink['subscriptionClient'].close(); I have created some logout logic like so resetStore(): Promise<ApolloQueryResult<any>[]> {
this.webSocketLink['subscriptionClient'].close();
return this.apollo.getClient().resetStore();
} I have also created apollo graphql client for angular especially for Gapi (Server Side Easy Api based on Apollo) but can be used in other Graphql Servers check this out |
* Add `clearStore` method A new `clearStore` method has been added, that will remove all data from the store. Unlike `resetStore`, it will not refetch active queries after removing store data. Fixes #2411. Fixes #2774. Fixes #3539. Fixes #3813. * Changelog update * Add `clearStore` to API docs * Add `clearStore` reference to authentication docs * Add `clearStore` reference to caching docs
#3885 adds a new |
how to use the new clearStore function? |
@cheuk3 Should be available once the next apollo-client release is published. |
Does |
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 thatlocalStorage.clear()
(or whatever methodology you're using to persist data locally's clear out function).The text was updated successfully, but these errors were encountered: