From 4628a90be200d2f5f058fb123cfeda2a3beded55 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Fri, 5 Apr 2024 09:41:22 +0200 Subject: [PATCH 1/3] fix: checkif tokens are present when setting user is logged in --- src/apps/main/auth/handlers.ts | 6 +++++- src/apps/main/auth/service.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/apps/main/auth/handlers.ts b/src/apps/main/auth/handlers.ts index 5303e14e8..5ba99b65e 100644 --- a/src/apps/main/auth/handlers.ts +++ b/src/apps/main/auth/handlers.ts @@ -16,10 +16,14 @@ import { logout, obtainToken, setCredentials, + tokensArePresent, } from './service'; let isLoggedIn: boolean; -setIsLoggedIn(!!getUser()); + +if (getUser() && tokensArePresent()) { + setIsLoggedIn(true); +} export function setIsLoggedIn(value: boolean) { isLoggedIn = value; diff --git a/src/apps/main/auth/service.ts b/src/apps/main/auth/service.ts index a9940714a..4c173730a 100644 --- a/src/apps/main/auth/service.ts +++ b/src/apps/main/auth/service.ts @@ -152,6 +152,14 @@ export function obtainToken(tokenName: TokenKey): string { return safeStorage.decryptString(buffer); } +export function tokensArePresent(): boolean { + const tokens = tokensKeys + .map((token) => ConfigStore.get(token)) + .filter((token) => token && token.length !== 0); + + return tokens.length === tokensKeys.length; +} + export function obtainTokens(): Array { return tokensKeys.map(obtainToken); } From c54e0b5aed747624d15f24af598ee5fa2c188199 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Fri, 5 Apr 2024 10:07:14 +0200 Subject: [PATCH 2/3] chore: remove ipcRender from preload --- src/apps/main/preload.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/main/preload.js b/src/apps/main/preload.js index 684bac92f..1f43ebb9f 100644 --- a/src/apps/main/preload.js +++ b/src/apps/main/preload.js @@ -297,5 +297,4 @@ contextBridge.exposeInMainWorld('electron', { return ipcRenderer.invoke('APP:PREFERRED_LANGUAGE'); }, path, - ipcRenderer, }); From 2bf90aeb17dbbdd82f59c90328a40436f6d70204 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Fri, 5 Apr 2024 10:09:29 +0200 Subject: [PATCH 3/3] fix: ensure isLoggedIn is initialized --- src/apps/main/auth/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/main/auth/handlers.ts b/src/apps/main/auth/handlers.ts index 5ba99b65e..d9a254ee0 100644 --- a/src/apps/main/auth/handlers.ts +++ b/src/apps/main/auth/handlers.ts @@ -19,7 +19,7 @@ import { tokensArePresent, } from './service'; -let isLoggedIn: boolean; +let isLoggedIn = false; if (getUser() && tokensArePresent()) { setIsLoggedIn(true);