From cf5d5261766eaba937be29dbfc22c0077d9319ca Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sun, 7 Jun 2026 03:23:17 +0000 Subject: [PATCH] Show CoinPay connection status on homepage Checks /api/oauth/coinpay/session on load and updates the Connect button to reflect the authenticated user's email when already connected. Also cleans the coinpay_oauth query param from the URL after OAuth callback. Co-Authored-By: Claude Sonnet 4.6 --- apps/logicsrc-web/src/main.ts | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/logicsrc-web/src/main.ts b/apps/logicsrc-web/src/main.ts index 3ec6b61..26b9fb3 100644 --- a/apps/logicsrc-web/src/main.ts +++ b/apps/logicsrc-web/src/main.ts @@ -498,3 +498,40 @@ const pageRoute = window.location.pathname.slice(1); if (["docs", "blog", "openspec", "credential-sharing", "hire-us", "about", "terms", "privacy"].includes(pageRoute)) { document.querySelector(`#${pageRoute}`)?.scrollIntoView(); } + +// CoinPay OAuth connection status +const coinpayParam = new URLSearchParams(window.location.search).get("coinpay_oauth"); +if (coinpayParam) { + const url = new URL(window.location.href); + url.searchParams.delete("coinpay_oauth"); + url.searchParams.delete("error"); + history.replaceState(null, "", url.pathname + (url.search || "")); +} + +async function updateCoinPayButton() { + const connectBtn = document.querySelector(".hero-actions a[href='/api/oauth/coinpay/start']"); + if (!connectBtn) return; + + try { + const res = await fetch("/api/oauth/coinpay/session"); + const data = await res.json(); + + if (data.authenticated && data.user) { + const label = data.user.email || data.user.name || data.user.sub || "CoinPay"; + connectBtn.textContent = `Connected: ${label}`; + connectBtn.style.background = "#3a9e7e"; + connectBtn.removeAttribute("href"); + connectBtn.style.cursor = "default"; + connectBtn.title = `Connected via CoinPay since ${new Date(data.user.connected_at).toLocaleDateString()}`; + } else if (coinpayParam === "connected") { + connectBtn.textContent = "CoinPay Connected"; + connectBtn.style.background = "#3a9e7e"; + } else if (coinpayParam === "error") { + connectBtn.textContent = "Connect CoinPay (retry)"; + } + } catch { + // session check failed — leave button as-is + } +} + +updateCoinPayButton();