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

@@ -53,18 +53,7 @@ const addGameToLibrary = async (
const game = await gameRepository.findOne({ where: { objectID } });
createGame(game!).then((response) => {
const {
id: remoteId,
playTimeInMilliseconds,
lastTimePlayed,
} = response.data;
gameRepository.update(
{ objectID },
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
);
});
createGame(game!);
});
};

View File

@@ -19,7 +19,7 @@ const removeGameFromLibrary = async (
const removeRemoveGameFromLibrary = async (gameId: number) => {
const game = await gameRepository.findOne({ where: { id: gameId } });
if (game?.remoteId) {
if (game?.remoteId && HydraApi.isLoggedIn()) {
HydraApi.delete(`/games/${game.remoteId}`);
}
};

View File

@@ -8,6 +8,8 @@ import { logger } from "@main/services";
const getMe = async (
_event: Electron.IpcMainInvokeEvent
): Promise<UserProfile | null> => {
if (!HydraApi.isLoggedIn()) return null;
return HydraApi.get(`/profile/me`)
.then((response) => {
const me = response.data;

View File

@@ -95,18 +95,7 @@ const startGameDownload = async (
},
});
createGame(updatedGame!).then((response) => {
const {
id: remoteId,
playTimeInMilliseconds,
lastTimePlayed,
} = response.data;
gameRepository.update(
{ objectID },
{ remoteId, playTimeInMilliseconds, lastTimePlayed }
);
});
createGame(updatedGame!);
await downloadQueueRepository.delete({ game: { id: updatedGame!.id } });
await downloadQueueRepository.insert({ game: { id: updatedGame!.id } });

View File

@@ -9,6 +9,8 @@ const getUser = async (
_event: Electron.IpcMainInvokeEvent,
userId: string
): Promise<UserProfile | null> => {
if (!HydraApi.isLoggedIn()) return null;
try {
const response = await HydraApi.get(`/user/${userId}`);
const profile = response.data;