Fix USER_ID TDZ error in Firefox by using window.USER_ID
All checks were successful
Build and push Docker image / build (push) Successful in 13s
Test / test (push) Successful in 15s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
marwin 2026-03-19 20:59:12 +01:00
parent 93dcae84d3
commit c965da6891

View file

@ -1813,7 +1813,7 @@ function hexToBytes(hex) {
async function getOrCreateEncKey() {
if (_encKey) return _encKey;
const storageKey = `diora_enc_key_${typeof USER_ID !== 'undefined' ? USER_ID : 'anon'}`;
const storageKey = `diora_enc_key_${window.USER_ID || 'anon'}`;
const stored = localStorage.getItem(storageKey);
if (stored) {
try {
@ -2605,7 +2605,7 @@ function showImportKey() {
const raw = base64ToBytes(b64);
const importedKey = await crypto.subtle.importKey('raw', raw, {name: 'AES-GCM', length: 256}, true, ['encrypt', 'decrypt']);
const re_exported = await crypto.subtle.exportKey('raw', importedKey);
localStorage.setItem(`diora_enc_key_${USER_ID}`, bytesToBase64(re_exported));
localStorage.setItem(`diora_enc_key_${window.USER_ID}`, bytesToBase64(re_exported));
closeSidebar();
if (statusEl) statusEl.textContent = '✓ Key imported — reloading books…';
await loadBookList();
@ -3828,10 +3828,10 @@ async function saveFocusStation(url, name) {
(function init() {
// Migrate PBKDF2-derived key stored by login/register form
if (typeof USER_ID !== 'undefined' && USER_ID) {
if (window.USER_ID) {
const pending = localStorage.getItem('diora_pending_enc_key');
if (pending) {
localStorage.setItem(`diora_enc_key_${USER_ID}`, pending);
localStorage.setItem(`diora_enc_key_${window.USER_ID}`, pending);
localStorage.removeItem('diora_pending_enc_key');
}
}