Skip to content

Commit

Permalink
fix: add 1s delay before trying to encrypt the credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanVicens committed Apr 4, 2024
1 parent de3280f commit 2414013
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/apps/main/auth/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 7 additions & 1 deletion src/apps/main/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 2414013

Please sign in to comment.