From 8d0ebdee17eaaa8770ef99a72ca00f53ddd69ed6 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Thu, 17 Nov 2022 13:13:09 -0500 Subject: [PATCH 1/2] Clear cache from React Query on logout --- app/soapbox/actions/auth.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/soapbox/actions/auth.ts b/app/soapbox/actions/auth.ts index 25b3f2196..5bdf1f327 100644 --- a/app/soapbox/actions/auth.ts +++ b/app/soapbox/actions/auth.ts @@ -16,6 +16,7 @@ import { obtainOAuthToken, revokeOAuthToken } from 'soapbox/actions/oauth'; import { startOnboarding } from 'soapbox/actions/onboarding'; import snackbar from 'soapbox/actions/snackbar'; import { custom } from 'soapbox/custom'; +import { queryClient } from 'soapbox/queries/client'; import KVStore from 'soapbox/storage/kv-store'; import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth'; import sourceCode from 'soapbox/utils/code'; @@ -239,10 +240,16 @@ export const logOut = () => token: state.auth.getIn(['users', account.url, 'access_token']), }; - return dispatch(revokeOAuthToken(params)).finally(() => { - dispatch({ type: AUTH_LOGGED_OUT, account, standalone }); - return dispatch(snackbar.success(messages.loggedOut)); - }); + return dispatch(revokeOAuthToken(params)) + .finally(() => { + // Clear all stored cache from React Query + queryClient.invalidateQueries(); + queryClient.clear(); + + dispatch({ type: AUTH_LOGGED_OUT, account, standalone }); + + return dispatch(snackbar.success(messages.loggedOut)); + }); }; export const switchAccount = (accountId: string, background = false) => From 4c9006609c785f6ebb2239c05aecc021217d6f3f Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Fri, 18 Nov 2022 10:25:24 -0500 Subject: [PATCH 2/2] Clear cache from React Query on change account --- app/soapbox/actions/auth.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/soapbox/actions/auth.ts b/app/soapbox/actions/auth.ts index 5bdf1f327..d588db80a 100644 --- a/app/soapbox/actions/auth.ts +++ b/app/soapbox/actions/auth.ts @@ -255,6 +255,10 @@ export const logOut = () => export const switchAccount = (accountId: string, background = false) => (dispatch: AppDispatch, getState: () => RootState) => { const account = getState().accounts.get(accountId); + // Clear all stored cache from React Query + queryClient.invalidateQueries(); + queryClient.clear(); + return dispatch({ type: SWITCH_ACCOUNT, account, background }); };