From 24140130d170a11eb855d44d0f56ffb004cc93e9 Mon Sep 17 00:00:00 2001 From: joan vicens Date: Thu, 4 Apr 2024 12:43:07 +0200 Subject: [PATCH] fix: add 1s delay before trying to encrypt the credentials --- src/apps/main/auth/handlers.ts | 7 ++++++- src/apps/main/auth/service.ts | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/apps/main/auth/handlers.ts b/src/apps/main/auth/handlers.ts index f1b96553d..5303e14e8 100644 --- a/src/apps/main/auth/handlers.ts +++ b/src/apps/main/auth/handlers.ts @@ -59,7 +59,12 @@ ipcMain.on('user-is-unauthorized', onUserUnauthorized); ipcMain.on('user-logged-in', async (_, data: AccessResponse) => { try { - setCredentials(data.user, data.user.mnemonic, data.token, data.newToken); + await setCredentials( + data.user, + data.user.mnemonic, + data.token, + data.newToken + ); if (!canHisConfigBeRestored(data.user.uuid)) { await setupRootFolder(); } diff --git a/src/apps/main/auth/service.ts b/src/apps/main/auth/service.ts index 57c110a03..a9940714a 100644 --- a/src/apps/main/auth/service.ts +++ b/src/apps/main/auth/service.ts @@ -4,6 +4,7 @@ import Logger from 'electron-log'; import packageConfig from '../../../../package.json'; import ConfigStore, { defaults, fieldsToSave } from '../config'; import { User } from '../types'; +import { Delay } from '../../shared/Delay'; const TOKEN_ENCODING = 'latin1'; @@ -39,7 +40,7 @@ function ecnryptToken(token: string): string { return buffer.toString(TOKEN_ENCODING); } -export function setCredentials( +export async function setCredentials( userData: User, mnemonic: string, bearerToken: string, @@ -48,6 +49,11 @@ export function setCredentials( ConfigStore.set('mnemonic', mnemonic); ConfigStore.set('userData', userData); + await Delay.ms(1_000); + // In the version of electron we are using calling + // isEncryptionAvailable or decryptString "too son" will crash the app + // we will be able to remove once we can update the electron version + const isSafeStorageAvailable = safeStorage.isEncryptionAvailable(); const token = isSafeStorageAvailable