From 2321b80127582de1c24155a621e26371560b49a8 Mon Sep 17 00:00:00 2001 From: marwin Date: Thu, 19 Mar 2026 21:14:16 +0100 Subject: [PATCH] Auto-generate encryption key if none exists instead of throwing Co-Authored-By: Claude Sonnet 4.6 --- static/js/app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/static/js/app.js b/static/js/app.js index dbbd627..b2c7855 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1820,9 +1820,12 @@ async function getOrCreateEncKey() { const raw = base64ToBytes(stored); _encKey = await crypto.subtle.importKey('raw', raw, {name: 'AES-GCM'}, false, ['encrypt', 'decrypt']); return _encKey; - } catch (e) { /* fall through */ } + } catch (e) { /* fall through, generate new */ } } - throw new Error('No encryption key found. Please log out and log in again to unlock encrypted content.'); + _encKey = await crypto.subtle.generateKey({name: 'AES-GCM', length: 256}, true, ['encrypt', 'decrypt']); + const raw = await crypto.subtle.exportKey('raw', _encKey); + localStorage.setItem(storageKey, bytesToBase64(new Uint8Array(raw))); + return _encKey; } async function encryptBytes(key, plainBytes) {