Skip to content
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

fix: logs user out on error #1271

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export const useGetAirdropUserDetails = () => {
const baseUrl = useAirdropStore((state) => state.backendInMemoryConfig?.airdropApiUrl);
const airdropToken = useAirdropStore((state) => state.airdropTokens?.token);
const userDetails = useAirdropStore((state) => state.userDetails);

Check warning on line 8 in src/hooks/airdrop/stateHelpers/useGetAirdropUserDetails.ts

View workflow job for this annotation

GitHub Actions / Run linters

'userDetails' is assigned a value but never used. Allowed unused vars must match /^_/u
const setUserDetails = useAirdropStore((state) => state.setUserDetails);
const setUserPoints = useAirdropStore((state) => state.setUserPoints);
const setReferralCount = useAirdropStore((state) => state.setReferralCount);
Expand All @@ -13,19 +13,29 @@
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<UserDetails>({
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 () => {
Expand Down Expand Up @@ -83,9 +93,9 @@
await Promise.all(requests);
};

if (!userDetails?.user?.id && airdropToken) {
if (airdropToken) {
fetchData();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [airdropToken, userDetails, baseUrl]);
}, [airdropToken, baseUrl]);
};
Loading