Skip to content

Commit

Permalink
app: invalidate queries as part of signin/signout callback
Browse files Browse the repository at this point in the history
Need some time for cookie response to settle it seems. Something like 100ms
sometimes doesn't seem enough.
  • Loading branch information
kahkeng committed Jul 15, 2023
1 parent e168a67 commit d87cdf4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/contexts/ConnectionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand All @@ -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 = ({
Expand Down

0 comments on commit d87cdf4

Please sign in to comment.