diff --git a/server.js b/server.js index a267896..8186eb9 100644 --- a/server.js +++ b/server.js @@ -2510,7 +2510,9 @@ const server = http.createServer(async (req, res) => { // -- Gem Kingdom hand-off (2026-10-01): sign the member across; the game verifies with GK_SSO_SECRET if (p === '/api/my/gemkingdom' && req.method === 'GET') { const s = await auth.fromRequest(req); - if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Set-Cookie': gkCookie('iap.return', 'gemkingdom', 1800), 'Cache-Control': 'no-store' }); return res.end(); } + // a newcomer from a Gem Kingdom feed post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor + const gkRef = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); + if (!s || !s.email) { res.writeHead(302, { Location: '/my' + (gkRef ? '?ref=' + encodeURIComponent(gkRef) : ''), 'Set-Cookie': gkCookie('iap.return', 'gemkingdom', 1800), 'Cache-Control': 'no-store' }); return res.end(); } if (GK_SECRET().length < 32) return json(res, 503, { error: 'Gem Kingdom is not connected yet.' }); const acct = await accounts.byEmail(s.email); const tok = gkMint({ memberId: Number((acct && acct.memberId) || s.memberId || 0), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null });