From 1d1fcb8b8161dafaf867302175c28f3100e6b1e3 Mon Sep 17 00:00:00 2001 From: Juan De Luca Date: Mon, 16 Dec 2024 11:55:33 -0300 Subject: [PATCH 1/3] logs user out on error --- .../stateHelpers/useGetAirdropUserDetails.ts | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts index 8d9c7e537..700dc532a 100644 --- a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts +++ b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts @@ -13,19 +13,29 @@ export const useGetAirdropUserDetails = () => { const setBonusTiers = useAirdropStore((state) => state.setBonusTiers); const logout = useAirdropStore((state) => state.logout); + const handleErrorLogout = useCallback(() => { + console.error('Error fetching user details, logging out'); + logout(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + // GET USER DETAILS const fetchUserDetails = useCallback(async () => { return handleRequest({ path: '/user/details', method: 'GET', - onError: logout, - }).then((data) => { - if (data?.user?.id) { - setUserDetails(data); - return data.user; - } - }); - }, [handleRequest, logout, setUserDetails]); + onError: handleErrorLogout, + }) + .then((data) => { + if (data?.user?.id) { + setUserDetails(data); + return data.user; + } else { + handleErrorLogout(); + } + }) + .catch(() => handleErrorLogout()); + }, [handleRequest, setUserDetails, handleErrorLogout]); // GET USER POINTS const fetchUserPoints = useCallback(async () => { From 3f5d5b42b7b8d1dea2d5bedef08d0b5e2fc6c348 Mon Sep 17 00:00:00 2001 From: Juan De Luca Date: Mon, 16 Dec 2024 11:57:42 -0300 Subject: [PATCH 2/3] update --- src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts index 700dc532a..2327ab4a6 100644 --- a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts +++ b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts @@ -93,7 +93,7 @@ export const useGetAirdropUserDetails = () => { await Promise.all(requests); }; - if (!userDetails?.user?.id && airdropToken) { + if (airdropToken) { fetchData(); } // eslint-disable-next-line react-hooks/exhaustive-deps From 8b37bcec5268e76b3028e1d71a84d695ea4cea5e Mon Sep 17 00:00:00 2001 From: Juan De Luca Date: Mon, 16 Dec 2024 11:58:08 -0300 Subject: [PATCH 3/3] removes dep --- src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts index 2327ab4a6..508c1da42 100644 --- a/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts +++ b/src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts @@ -97,5 +97,5 @@ export const useGetAirdropUserDetails = () => { fetchData(); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [airdropToken, userDetails, baseUrl]); + }, [airdropToken, baseUrl]); };