Skip to content

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

core: fix `ciphertext cannot be decrypted...` error on attachment upload after sign up (#9596)

01zulfi91077dc132ad
diff --git a/packages/core/src/api/key-manager.ts b/packages/core/src/api/key-manager.ts
index b5290b1ad..5ede493f3 100644
--- a/packages/core/src/api/key-manager.ts
+++ b/packages/core/src/api/key-manager.ts
@@ -83,8 +83,9 @@ export class KeyManager {
refetchUser?: boolean;
} = { refetchUser: true, useCache: true }
): Promise<KeyTypeFromId<TId> | undefined> {
- if (options.useCache && this.cache.has(id)) {
- return this.cache.get(id) as KeyTypeFromId<TId>;
+ const cachedKey = this.cache.get(id);
+ if (options.useCache && cachedKey) {
+ return cachedKey as KeyTypeFromId<TId>;
}
let user = await this.db.user.getUser();
if ((!user || !user[id]) && options.refetchUser) {
@@ -92,8 +93,10 @@ export class KeyManager {
}
if (!user) return;
- this.cache.set(id, user[id] as KeyTypeFromId<KeyId>);
- return user[id] as KeyTypeFromId<TId>;
+ const key = user[id] as KeyTypeFromId<TId>;
+ if (key) this.cache.set(id, key as KeyTypeFromId<KeyId>);
+
+ return key;
}
async unwrapKey<T extends WrappedKey>(