Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix vault key not getting synced

Abdullah Atta7b08b5c03530
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;
}