openvibers/openvibe.network Commits
Signed out, the account hub asks no API on its way to /login (history, themes and notifications logged 401s) (#316)
Changes
@@@ -4,9 +4,13 @@my/core.js's helpers (apiFetch, getAuthToken, showSection, API) and onmy/boot.js (loaded last), which starts the page. No ES modules.═══════════════════════════════════════════════════════════════ */--// Init++// Init. Signed out, loadUser() sends the visitor to /login: the section and the badge stay unasked, so the page never++// calls an API that answers 401 on the way there (/history, /themes and /notifications logged two each).OpenVibeAccountSwitcher.init({ apiBase: API });++const _signedIn = !!(getAuthToken() || getAnonToken());loadUser();buildDashboardShowcase();--openInitialSection();--refreshApprovalsBadge();++if (_signedIn) {++ openInitialSection();++ refreshApprovalsBadge();++}@@@ -38,7 +38,10 @@ assert.ok(html.includes('id="sec-approvals"') && html.includes('id="approvals-liconst approvals = fs.readFileSync(path.join(pub, 'js', 'my', 'approvals.js'), 'utf8');assert.ok(!/innerHTML|insertAdjacentHTML/.test(approvals), 'approvals.js never parses agent text as HTML');for (const name of ['loadApprovals', 'decideApproval', 'refreshApprovalsBadge']) assert.strictEqual(owner.get(name), 'approvals.js', `${name} lives in approvals.js`);--assert.ok(fs.readFileSync(path.join(pub, 'js', 'my', 'boot.js'), 'utf8').includes('refreshApprovalsBadge()'), 'boot.js shows the waiting count on the tab');++const bootSrc = fs.readFileSync(path.join(pub, 'js', 'my', 'boot.js'), 'utf8');++assert.ok(bootSrc.includes('refreshApprovalsBadge()'), 'boot.js shows the waiting count on the tab');++// Signed out (loadUser() redirects to /login), no section loads and no badge is asked for: each would answer 401.++assert.match(bootSrc, /if \(_signedIn\) \{\s*openInitialSection\(\);\s*refreshApprovalsBadge\(\);\s*\}/, 'signed out, boot.js asks no API');// The host is a SubjectRef object: the row names its id, never "[object Object]"; an anonymous session calls no API.{const vm = require('vm');
@@ -4,9 +4,13 @@
@@ -4,9 +4,13 @@
my/core.js's helpers (apiFetch, getAuthToken, showSection, API) and on
my/core.js's helpers (apiFetch, getAuthToken, showSection, API) and on
my/boot.js (loaded last), which starts the page. No ES modules.
my/boot.js (loaded last), which starts the page. No ES modules.
═══════════════════════════════════════════════════════════════ */
═══════════════════════════════════════════════════════════════ */
-// Init
+// Init. Signed out, loadUser() sends the visitor to /login: the section and the badge stay unasked, so the page never
+// calls an API that answers 401 on the way there (/history, /themes and /notifications logged two each).
OpenVibeAccountSwitcher.init({ apiBase: API });
OpenVibeAccountSwitcher.init({ apiBase: API });
+const _signedIn = !!(getAuthToken() || getAnonToken());
loadUser();
loadUser();
buildDashboardShowcase();
buildDashboardShowcase();
-openInitialSection();
-refreshApprovalsBadge();
+if (_signedIn) {
+ openInitialSection();
+ refreshApprovalsBadge();
+}
@@ -38,7 +38,10 @@ assert.ok(html.includes('id="sec-approvals"') && html.includes('id="approvals-li
@@ -38,7 +38,10 @@ assert.ok(html.includes('id="sec-approvals"') && html.includes('id="approvals-li
const approvals = fs.readFileSync(path.join(pub, 'js', 'my', 'approvals.js'), 'utf8');
const approvals = fs.readFileSync(path.join(pub, 'js', 'my', 'approvals.js'), 'utf8');
assert.ok(!/innerHTML|insertAdjacentHTML/.test(approvals), 'approvals.js never parses agent text as HTML');
assert.ok(!/innerHTML|insertAdjacentHTML/.test(approvals), 'approvals.js never parses agent text as HTML');
for (const name of ['loadApprovals', 'decideApproval', 'refreshApprovalsBadge']) assert.strictEqual(owner.get(name), 'approvals.js', `${name} lives in approvals.js`);
for (const name of ['loadApprovals', 'decideApproval', 'refreshApprovalsBadge']) assert.strictEqual(owner.get(name), 'approvals.js', `${name} lives in approvals.js`);
-assert.ok(fs.readFileSync(path.join(pub, 'js', 'my', 'boot.js'), 'utf8').includes('refreshApprovalsBadge()'), 'boot.js shows the waiting count on the tab');
+const bootSrc = fs.readFileSync(path.join(pub, 'js', 'my', 'boot.js'), 'utf8');
+assert.ok(bootSrc.includes('refreshApprovalsBadge()'), 'boot.js shows the waiting count on the tab');
+// Signed out (loadUser() redirects to /login), no section loads and no badge is asked for: each would answer 401.
+assert.match(bootSrc, /if \(_signedIn\) \{\s*openInitialSection\(\);\s*refreshApprovalsBadge\(\);\s*\}/, 'signed out, boot.js asks no API');
// The host is a SubjectRef object: the row names its id, never "[object Object]"; an anonymous session calls no API.
// The host is a SubjectRef object: the row names its id, never "[object Object]"; an anonymous session calls no API.
{
{
const vm = require('vm');
const vm = require('vm');