Merge network sign-in (InstantAdPay <-> LinkSpin) into main for the Friday launch (Marty 2026-11-13: 'we need to get that done now'). Conflicts only in script version tags (kept today's newer assets, re-tagged ?v=20261113sso). networksso.test 'ALL PASSED' both repos, networksso.e2e ALL PASSED, iap-qa member ALL PASSED. NETWORK_SSO_SECRET set on both Coolify apps. Chatbot KNOWLEDGE_DATE 2026-11-13.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-13 04:53:08 -06:00
10 changed files with 606 additions and 7 deletions
+25 -1
View File
@@ -17,6 +17,7 @@ const chain = require('./chain');
const auth = require('./auth');
const accounts = require('./accounts');
const forumsso = require('./forumsso'); // Earners Corner forum sign-in (DiscourseConnect, 2026-11-10)
const networksso = require('./networksso'); // network sign-in with LinkSpin (2026-11-12, Marty approved): see networksso.js
const themehead = require('./themehead'); // 2026-11-01 light/dark theme head script for server-rendered pages + its CSP hash
const ads = require('./ads');
const mailer = require('./mailer');
@@ -563,6 +564,27 @@ async function boot() {
}).catch(e => console.error('marks claim', e.message));
} });
auth.init({ dataDir: DATA_DIR, chain, isProd: IS_PROD, site: 'instantadpay.com' });
// network sign-in (2026-11-12): a member signed in on LinkSpin arrives here signed in, and the other way round. Member sessions
// only (the admin portal is never shared); an account that is not here yet, or is still a waiting LinkSpin/BTC4Hits account,
// gets the normal email-code sign-in with the email filled in, so every new-account check (anti-fraud, sponsor) runs as before.
networksso.init({ self: 'iap', peer: 'linkspin', peerBase: LS_BASE, isProd: IS_PROD, dataDir: DATA_DIR, db, defaultPath: '/my',
member: async req => { const s = await auth.fromRequest(req); return s && s.email && !fraud.isSuspended(s.email) ? s : null; },
accept: async email => {
const a = await accounts.byEmail(email);
if (!a) return { fallback: 'no account here yet' };
if (accounts.isUnclaimedShell(a)) return { fallback: 'waiting account, first sign-in needs the code' };
if (fraud.isSuspended(email) || fraud.isBlocked(email)) return { fallback: 'suspended or blocked' };
return { ok: true };
},
signIn: async (email, req) => { // the same session the email code makes (4 hours, same rights)
const a = await accounts.byEmail(email); let memberId = 0;
if (a && a.address) { try { memberId = await chain.memberIdByAccount(a.address); } catch (e) {} }
fraud.recordSeen(email, req).catch(() => {});
return auth.sessionCookie(await auth.mintSession({ email: a.email, address: a.address, memberId }));
},
// the dashboard runs the welcome tour / login ad after a sign-in (?welcome=1, the same step a code sign-in takes)
landing: to => { const x = new URL(to, 'http://x'); if (x.pathname === '/my') x.searchParams.set('welcome', '1'); return x.pathname + x.search + x.hash; },
signinPath: to => { const x = new URL(to, 'http://x'); return x.pathname === '/my' ? '/my' + x.hash : '/my'; } });
accounts.init({ dataDir: DATA_DIR });
ads.init({ dataDir: DATA_DIR, chain, tiers: () => geo.tierLists(siteConfig()) });
mailer.init({ dataDir: DATA_DIR });
@@ -2285,6 +2307,8 @@ const server = http.createServer(async (req, res) => {
const to = 'https://instantadpay.com' + (p === '/' ? '/' : ref ? '/join/' + ref[1] : p) + (u.search || '');
res.writeHead(302, { Location: to, 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' }); return res.end();
} }
// network sign-in with LinkSpin (2026-11-12): /go/linkspin, /sso/start, /sso/check, /sso/in, /api/sso/status
if (req.method === 'GET' && (p === '/go/linkspin' || p.startsWith('/sso/') || p === '/api/sso/status') && await networksso.handle(req, res, u)) return;
// a LinkSpin click arriving on any page (?lsclk= or ?lsid=): the first-party cookie, 30 days, last click wins (reporting only, lsreport.js).
// Added to whatever the page sends, like the viral-link cookies below.
@@ -2945,7 +2969,7 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/auth/logout' && req.method === 'POST') {
await auth.logout(req);
return json(res, 200, { ok: true }, { 'Set-Cookie': auth.clearCookie() });
return json(res, 200, { ok: true }, { 'Set-Cookie': [auth.clearCookie(), networksso.offCookie()] }); // signed out stays signed out: no silent network sign-in here for 12 hours
}
if (p === '/api/gas' && req.method === 'GET') {
try { return json(res, 200, await chain.suggestedFees()); }