Invite link: GET shows a sign-in button, POST spends the token (link previews were consuming it)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-29 19:34:34 -05:00
parent 418b89956c
commit 15f663a56d
+6 -1
View File
@@ -895,9 +895,14 @@ const server = http.createServer(async (req, res) => {
} }
if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, { 'Access-Control-Allow-Origin': '*' }); return res.end(); } if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, { 'Access-Control-Allow-Origin': '*' }); return res.end(); }
{ const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } } { const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } }
{ const wm = /^\/welcome\/([a-f0-9]{48})$/.exec(p); if (wm && req.method === 'GET') { // one-time tester sign-in link { const wm = /^\/welcome\/([a-f0-9]{48})$/.exec(p); if (wm && (req.method === 'GET' || req.method === 'POST')) { // one-time tester sign-in link
const t = inviteTokens.get(wm[1]); const t = inviteTokens.get(wm[1]);
if (!t || t.exp < Date.now()) { inviteTokens.delete(wm[1]); res.writeHead(410, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end('<!doctype html><meta charset="utf-8"><title>Link used</title><p style="font:15px system-ui;padding:24px">That sign-in link was already used or has expired. Ask for a fresh one.</p>'); } if (!t || t.exp < Date.now()) { inviteTokens.delete(wm[1]); res.writeHead(410, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end('<!doctype html><meta charset="utf-8"><title>Link used</title><p style="font:15px system-ui;padding:24px">That sign-in link was already used or has expired. Ask for a fresh one.</p>'); }
// GET only shows a button: link-preview fetchers and in-app browsers prefetch links, and a prefetch must not spend the token
if (req.method === 'GET') {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' });
return res.end('<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Sign in to LinkSpin</title></head><body style="margin:0;min-height:100vh;display:grid;place-items:center;background:#0B1424;font-family:Manrope,\'Segoe UI\',system-ui,sans-serif;color:#EEF3FA"><form method="post" style="background:#101D33;border:1px solid #1E2E4A;border-radius:12px;padding:28px 26px;width:min(420px,92vw);text-align:center"><div style="width:34px;height:34px;border-radius:50%;border:3px solid #1F6FEB;border-right-color:transparent;margin:0 auto 14px"></div><div style="font:700 11px monospace;letter-spacing:.14em;color:#8CA2C4">LINKSPIN TEST APP</div><h1 style="font:700 24px/1.2 \'Segoe UI\',system-ui;margin:8px 0 6px">Sign in as</h1><div style="font:500 14px monospace;color:#8CC8FF;margin-bottom:20px">' + esc(t.email) + '</div><button type="submit" style="font:700 15px \'Segoe UI\',system-ui;letter-spacing:.06em;text-transform:uppercase;background:linear-gradient(180deg,#FF7A32,#FF6A1A);color:#fff;border:1px solid #D9530A;border-radius:8px;padding:12px 22px;cursor:pointer;width:100%">Sign me in</button><p style="font-size:12px;color:#8CA2C4;margin:14px 0 0">One use. Good for 24 hours from when it was made.</p></form></body></html>');
}
inviteTokens.delete(wm[1]); inviteTokens.delete(wm[1]);
const acct = await accounts.byEmail(t.email); let memberId = 0; if (acct && acct.address) { try { memberId = await chain.memberIdByAccount(acct.address); } catch (e) {} } const acct = await accounts.byEmail(t.email); let memberId = 0; if (acct && acct.address) { try { memberId = await chain.memberIdByAccount(acct.address); } catch (e) {} }
const token = await auth.mintSession({ email: t.email, address: (acct && acct.address) || null, memberId }); const token = await auth.mintSession({ email: t.email, address: (acct && acct.address) || null, memberId });