feat: prevent api calls when user is not logged in

This commit is contained in:
Zamitto 2024-07-01 15:48:52 -03:00
parent 9870213fff
commit dd23358a95
11 changed files with 39 additions and 43 deletions

View file

@ -98,6 +98,8 @@ export function App() {
fetchUserDetails().then((response) => {
if (response) updateUserDetails(response);
});
} else {
clearUserDetails();
}
});
}, [fetchUserDetails, updateUserDetails, dispatch]);

View file

@ -57,8 +57,14 @@ export function useUserDetails() {
);
const fetchUserDetails = useCallback(async () => {
return window.electron.getMe();
}, []);
return window.electron.getMe().then((userDetails) => {
if (userDetails == null) {
clearUserDetails();
}
return userDetails;
});
}, [clearUserDetails]);
const patchUser = useCallback(
async (displayName: string, imageProfileUrl: string | null) => {