From 7b08b5c03530c1eab97dfb02901438c5f340989e Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 2 Oct 2023 15:09:28 +0500 Subject: [PATCH] core: fix vault key not getting synced --- packages/core/src/api/sync/index.js | 14 ++++++++------ packages/core/src/api/vault.js | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core/src/api/sync/index.js b/packages/core/src/api/sync/index.js index 7d66dfc1a..ed9f7a6f2 100644 --- a/packages/core/src/api/sync/index.js +++ b/packages/core/src/api/sync/index.js @@ -263,12 +263,14 @@ class Sync { lastSynced ); - if (serverResponse.vaultKey) { - await this.merger.mergeItem( - "vaultKey", - serverResponse.vaultKey, - serverResponse.lastSynced - ); + if ( + serverResponse.vaultKey && + serverResponse.vaultKey.cipher !== null && + serverResponse.vaultKey.iv !== null && + serverResponse.vaultKey.salt !== null && + serverResponse.vaultKey.length > 0 + ) { + await this.db.vault._setKey(serverResponse.vaultKey); } this.connection.off("SendItems"); diff --git a/packages/core/src/api/vault.js b/packages/core/src/api/vault.js index 63ce67c28..5c1be944c 100644 --- a/packages/core/src/api/vault.js +++ b/packages/core/src/api/vault.js @@ -179,6 +179,8 @@ export default class Vault { const note = this._db.notes.note(noteId); if (!note) return; await this._unlockNote(note.data, password, true); + + if (!this.exists()) await this.create(password); } /** @@ -192,6 +194,7 @@ export default class Vault { const unlockedNote = await this._unlockNote(note.data, password, false); this._password = password; + if (!this.exists()) await this.create(this._password); return unlockedNote; }