Decouple i18n from feature modules and fix auth/login UX

Replace hardcoded updateAllText() calls with languageChanged event
pattern so feature modules subscribe independently. Guard all API
calls behind apiKey checks to prevent unauthorized requests when not
logged in. Fix login modal localization, hide tabs when logged out,
clear all panels on logout, and treat profiles with no conditions as
always-true.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 12:32:14 +03:00
parent 747cdfabd6
commit 6388e0defa
13 changed files with 81 additions and 40 deletions

View File

@@ -307,12 +307,12 @@ window.addEventListener('beforeunload', () => {
// ─── Initialization ───
document.addEventListener('DOMContentLoaded', async () => {
// Initialize locale first
await initLocale();
// Load API key from localStorage
// Load API key from localStorage before anything that triggers API calls
setApiKey(localStorage.getItem('wled_api_key'));
// Initialize locale (dispatches languageChanged which may trigger API calls)
await initLocale();
// Restore active tab before showing content to avoid visible jump
initTabs();
@@ -326,7 +326,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (!apiKey) {
setTimeout(() => {
if (typeof window.showApiKeyModal === 'function') {
window.showApiKeyModal('Welcome! Please login with your API key to get started.', true);
window.showApiKeyModal(null, true);
}
}, 100);
return;