feat: use SSE reconnect to prevent API Key modal to pop up in dashboard if no API Key is configured

This commit is contained in:
Alpha Nerd 2026-06-07 09:29:06 +02:00
parent 497c87b02e
commit 75d204e7f3
Signed by: alpha-nerd
SSH key fingerprint: SHA256:QkkAgVoYi9TQ0UKPkiKSfnerZy2h4qhi3SVPXJmBN+M

View file

@ -1171,11 +1171,13 @@ function renderTimeSeriesChart(timeSeriesData, chart, minutes) {
}
};
source.onerror = async (err) => {
console.error("SSE connection error. Retrying...", err);
source.close();
await showApiKeyModal("Enter the NOMYO Router API key to view live usage.");
loadUsage();
source.onerror = (err) => {
// EventSource auto-reconnects on transient drops as long as we
// don't close it. Don't treat a dropped stream as an auth failure:
// auth prompting is handled by loadEndpoints()/authedFetch() on the
// REST endpoints. A genuine 401 closes the stream permanently here
// (no reconnect loop), and the REST path surfaces the modal.
console.error("SSE connection error; awaiting auto-reconnect.", err);
};
window.addEventListener("beforeunload", () => source.close());
}