diff --git a/static/account.js b/static/account.js index 6ca83fa..be8fa56 100644 --- a/static/account.js +++ b/static/account.js @@ -6,6 +6,8 @@ // every page the way units.js is (imported by each page's entry module). let currentUser = null; // {id, email, display_name} or null +let discordEnabled = false; // is Discord linking configured on the server? +let discordChecked = false; // have we asked yet? (once per page load) const authCbs = []; // notified on login/logout so pages can re-gate // The app's base path (e.g. "/thermograph"), derived from this module's own URL @@ -59,6 +61,16 @@ async function refreshUser() { const res = await apiFetch("api/v2/users/me"); currentUser = res.ok ? await res.json() : null; } catch (e) { currentUser = null; } + // Learn once whether Discord linking is configured, so the account menu only + // offers "Link Discord" when it will actually work (checked lazily, and only + // for a signed-in user — the menu never shows it to anyone else). + if (currentUser && !discordChecked) { + discordChecked = true; + try { + const r = await apiFetch("api/v2/discord/config"); + if (r.ok) discordEnabled = (await r.json()).enabled === true; + } catch (e) { /* leave it hidden */ } + } return currentUser; } @@ -304,7 +316,7 @@ function renderHeader() { ${currentUser.discord_id ? `` + '' - : `Link Discord`} + : (discordEnabled ? `Link Discord` : "")} `;