feat: add event and check if user is logged in

This commit is contained in:
Zamitto 2024-06-19 12:07:33 -03:00
parent 6b03705d54
commit 17cfc7bb02
6 changed files with 21 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import "./library/open-game-installer-path";
import "./library/update-executable-path";
import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/is-user-logged-in";
import "./misc/open-external";
import "./misc/show-open-dialog";
import "./torrenting/cancel-game-download";

View File

@ -0,0 +1,8 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services/hydra-api";
const isUserLoggedIn = async (_event: Electron.IpcMainInvokeEvent) => {
return HydraApi.isLoggedIn();
};
registerEvent("isUserLoggedIn", isUserLoggedIn);

View File

@ -14,6 +14,10 @@ export class HydraApi {
expirationTimestamp: 0,
};
static isLoggedIn() {
return this.userAuth.authToken !== "";
}
static async handleExternalAuth(auth: string) {
const { payload } = url.parse(auth, true).query;

View File

@ -106,6 +106,7 @@ contextBridge.exposeInMainWorld("electron", {
getVersion: () => ipcRenderer.invoke("getVersion"),
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
isUserLoggedIn: () => ipcRenderer.invoke("isUserLoggedIn"),
showOpenDialog: (options: Electron.OpenDialogOptions) =>
ipcRenderer.invoke("showOpenDialog", options),
platform: process.platform,

View File

@ -86,9 +86,12 @@ export function App() {
dispatch(setProfileBackground(profileBackground));
}
/* TODO: Check if user is logged in before calling this */
fetchUserDetails().then((response) => {
if (response) setUserDetails(response);
window.electron.isUserLoggedIn().then((isLoggedIn) => {
if (isLoggedIn) {
fetchUserDetails().then((response) => {
if (response) setUserDetails(response);
});
}
});
}, [dispatch, fetchUserDetails]);

View File

@ -96,6 +96,7 @@ declare global {
/* Misc */
openExternal: (src: string) => Promise<void>;
isUserLoggedIn: () => Promise<boolean>;
getVersion: () => Promise<string>;
ping: () => string;
getDefaultDownloadsPath: () => Promise<string>;