From d87cdf42a062cf7f9aa796793368f88d189f0c48 Mon Sep 17 00:00:00 2001 From: Kah Keng Tay Date: Fri, 14 Jul 2023 17:28:13 -0700 Subject: [PATCH] app: invalidate queries as part of signin/signout callback Need some time for cookie response to settle it seems. Something like 100ms sometimes doesn't seem enough. --- src/contexts/ConnectionWrapper.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/contexts/ConnectionWrapper.tsx b/src/contexts/ConnectionWrapper.tsx index 1eda562cb..90720cf3f 100644 --- a/src/contexts/ConnectionWrapper.tsx +++ b/src/contexts/ConnectionWrapper.tsx @@ -17,8 +17,11 @@ import useCachedState from '@/hooks/useCachedState'; import { getBackendApiUrl } from '@/utils/backend'; import { GetSiweMessageOptions, RainbowKitSiweNextAuthProvider } from '@/utils/rainbowSIWEmod'; import SettingsContext from './SettingsContext'; +import { useQueryClient } from 'react-query'; const ConnectionWrapper = ({ children, useSiwe = true }: any) => { + const queryClient = useQueryClient(); + /* Use a fork url cached in the browser localStorage, else use the .env value */ const [forkUrl] = useCachedState( 'forkUrl', @@ -73,6 +76,14 @@ const ConnectionWrapper = ({ children, useSiwe = true }: any) => { return nonce; }; + const invalidateQueries = () => { + // set timeout to allow cookie response to first be set prior to refetching + setTimeout(() => { + queryClient.invalidateQueries({ queryKey: ['chats'] }); + queryClient.invalidateQueries({ queryKey: ['shareSettings'] }); + }, 1000); + } + const getSigninCallback = async (message: string, signature: string) => { const backendUrl = getBackendApiUrl(); const result = await axios.post( @@ -83,12 +94,14 @@ const ConnectionWrapper = ({ children, useSiwe = true }: any) => { }, { withCredentials: true } ); + invalidateQueries(); return !!result.data; }; const getSignoutCallback = async () => { const backendUrl = getBackendApiUrl(); await axios.post(`${backendUrl}/logout`, {}, { withCredentials: true }); + invalidateQueries(); }; const CustomAvatar: AvatarComponent = ({