diff --git a/index.html b/index.html index 61dbb4b..54513e4 100644 --- a/index.html +++ b/index.html @@ -2377,22 +2377,42 @@ async function resolveIdentity() { const p = new URLSearchParams(window.location.search); const ctbParam = (p.get('ctb') || '').trim(); try { + // Members mix the two usernames up constantly, so each param tries its + // own direction FIRST, then rescues by trying the other (a CTB username + // pasted into ?ref=, or a CBP username pasted into ?ctb=, both resolve). if (ctbParam) { const r = await fetch(`${CTB_LOOKUP_URL}?ctb=${encodeURIComponent(ctbParam)}`).then(x => x.json()); if (r.found) { IDENT.cbp = r.cbpUsername; IDENT.ctb = r.ctbUsername; } else { - // No ClickBaitPays entry in their downline builder: CBP signups fall - // back to the team account, but the hub link still aligns them in CTB. - IDENT.ctb = ctbParam; - IDENT.fallback = true; + const rv = await fetch(`${CTB_LOOKUP_URL}?cbp=${encodeURIComponent(ctbParam)}`).then(x => x.json()); + if (rv.found) { + IDENT.cbp = rv.cbpUsername; + IDENT.ctb = rv.ctbUsername; + } else { + // No ClickBaitPays entry in their downline builder: CBP signups fall + // back to the team account, but the hub link still aligns them in CTB. + IDENT.ctb = ctbParam; + IDENT.fallback = true; + } } } else { // Legacy/current ?ref= links (or the default): reverse-resolve the CTB // username so the Team Hub invite personalizes to the same sponsor. const r = await fetch(`${CTB_LOOKUP_URL}?cbp=${encodeURIComponent(IDENT.cbp)}`).then(x => x.json()); - if (r.found) IDENT.ctb = r.ctbUsername; + if (r.found) { + IDENT.ctb = r.ctbUsername; + } else { + // Rescue: the ?ref= value may actually BE a CTB username (Marty hit + // this live 2026-08-01 with ?ref=). Forward-resolve it + // and adopt the member's real ClickBaitPays ref for the signup links. + const f = await fetch(`${CTB_LOOKUP_URL}?ctb=${encodeURIComponent(IDENT.cbp)}`).then(x => x.json()); + if (f.found) { + IDENT.cbp = f.cbpUsername; + IDENT.ctb = f.ctbUsername; + } + } } } catch (e) { // Lookup unreachable: defaults stand, nothing breaks.