Files
martbost 5585abb663 Network sign-in with LinkSpin (Marty approved 2026-11-12): signed in on one site = signed in on the other, no email code
networksso.js (same file in both repos): /go/linkspin hop for signed-in members' cross-site links; /sso/start (state cookie +
30-minute loop guard) -> LinkSpin /sso/check -> /sso/in?t=<v1 HMAC-SHA256 token, NETWORK_SSO_SECRET, 60 s, single-use nonce
(MySQL table network_sso_nonces when on the DB, else DATA_DIR file), bound to the browser's state cookie, email, audience and a
same-site relative path>. Member sessions only (admin portal never shared), ordinary 4-hour session, /my lands with ?welcome=1
so the login ad runs as after a code sign-in. An email with no account here or a waiting LinkSpin/BTC4Hits account gets the
normal email-code sign-in, email prefilled; nothing is created. Silent check on /my via public/assets/netsso.js
(/api/sso/status); never for bots/fetches; sign-out pauses it 12 hours. Engine Room + Fuel links go through /go/linkspin.
Chatbot knows it (KNOWLEDGE_DATE 2026-11-12). Off until NETWORK_SSO_SECRET (32+ chars) is set.

qa: networksso.test.cjs all passed, networksso.e2e.mjs (both servers, real browser) 31/31, run.sh member green (0 bugs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 07:00:23 -06:00

31 lines
1.8 KiB
JavaScript

// Network sign-in, the sign-in page side (2026-11-12). The SAME file ships in InstantAdPay and LinkSpin (see networksso.js).
// On a sign-in screen with no session: ask /api/sso/status once; { check: true } means bounce once through the other site,
// which signs the member in here if they are signed in there (the server allows one try per browser per 30 minutes and none
// after a sign-out). { hint } means they came from the other site but need the email code here the first time: fill it in.
(function () {
if (window.__netsso) return; window.__netsso = 1;
const BOXES = '#mcEmail,#jnEmail,#siEmail';
function fill(email, peer) {
let n = 0;
const t = setInterval(() => {
const el = document.querySelector(BOXES);
if (el && el.offsetParent !== null) {
clearInterval(t);
if (!el.value) el.value = email;
if (!document.getElementById('nssoNote')) {
const p = document.createElement('p'); p.id = 'nssoNote'; p.className = 'muted small'; p.setAttribute('role', 'note'); p.style.margin = '6px 0';
p.textContent = 'Welcome over from ' + peer + '. The first time here, send yourself a code with the same email to finish signing in. After that, ' + peer + ' signs you in here.';
(el.closest('label') || el).insertAdjacentElement('afterend', p);
}
try { el.focus(); } catch (e) {}
} else if (++n > 60) clearInterval(t);
}, 250);
}
fetch('/api/sso/status', { credentials: 'same-origin', headers: { Accept: 'application/json' }, cache: 'no-store' })
.then(r => r.json()).then(d => {
if (!d) return;
if (d.check) { location.replace('/sso/start?mode=check&to=' + encodeURIComponent(location.pathname + location.search + location.hash)); return; }
if (d.hint) fill(String(d.hint), String(d.peer || 'the other site'));
}).catch(() => {});
})();