Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: implement email functionality for user onboarding and verification

nirholas56d1f4602570
diff --git a/api/_lib/email.js b/api/_lib/email.js
new file mode 100644
index 000000000..a52f49976
--- /dev/null
+++ b/api/_lib/email.js
@@ -0,0 +1,156 @@
+// Transactional email via Resend. All sends are fire-and-forget — never await
+// them on the critical path. Import sendEmail and call without await.
+//
+// Required env: RESEND_API_KEY, EMAIL_FROM (e.g. "3D Agent <[email protected]>")
+// Optional env: EMAIL_REPLY_TO
+
+import { Resend } from 'resend';
+
+let _client = null;
+function client() {
+ if (!_client) _client = new Resend(process.env.RESEND_API_KEY);
+ return _client;
+}
+
+const FROM = process.env.EMAIL_FROM || '3D Agent <[email protected]>';
+const REPLY = process.env.EMAIL_REPLY_TO || null;
+const APP_URL = process.env.APP_ORIGIN || 'https://3dagent.xyz';
+
+// ─── Low-level send ───────────────────────────────────────────────────────────
+
+export async function sendEmail({ to, subject, html, text }) {
+ if (!process.env.RESEND_API_KEY) return; // no-op if not configured
+ try {
+ await client().emails.send({
+ from: FROM,
+ ...(REPLY ? { replyTo: REPLY } : {}),
+ to,
+ subject,
+ html,
+ text,
+ });
+ } catch (err) {
+ console.error('[email] send failed', err?.message);
+ }
+}
+
+// ─── Templates ───────────────────────────────────────────────────────────────
+
+export function sendWelcomeEmail({ to, displayName }) {
+ const name = displayName || 'there';
+ return sendEmail({
+ to,
+ subject: 'Welcome to 3D Agent',
+ html: welcomeHtml(name),
+ text: welcomeText(name),
+ });
+}
+
+export function sendVerificationEmail({ to, code, expiresInMinutes = 30 }) {
+ return sendEmail({
+ to,
+ subject: `${code} — verify your email`,
+ html: verifyHtml(code, expiresInMinutes),
+ text: verifyText(code, expiresInMinutes),
+ });
+}
+
+export function sendPasswordResetEmail({ to, resetUrl, expiresInMinutes = 60 }) {
+ return sendEmail({
+ to,
+ subject: 'Reset your 3D Agent password',
+ html: resetHtml(resetUrl, expiresInMinutes),
+ text: resetText(resetUrl, expiresInMinutes),
+ });
+}
+
+export function sendSubscriptionConfirmEmail({ to, plan, chain, txId }) {
+ return sendEmail({
+ to,
+ subject: `3D Agent ${capitalize(plan)} plan activated`,
+ html: subscriptionHtml(plan, chain, txId),
+ text: subscriptionText(plan, chain, txId),
+ });
+}
+
+// ─── HTML helpers ─────────────────────────────────────────────────────────────
+
+function layout(body) {
+ return `<!DOCTYPE html>
+<html lang="en">
+<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
+<style>
+ body{font-family:-apple-system,system-ui,'Segoe UI',sans-serif;background:#080814;color:#eee;margin:0;padding:32px 16px}
+ .card{max-width:520px;margin:0 auto;background:#14141c;border:1px solid #2a2a36;border-radius:16px;padding:36px 32px}
+ .brand{font-size:12px;letter-spacing:.1em;text-transform:uppercase;color:#6a5cff;margin:0 0 20px}
+ h1{font-size:22px;margin:0 0 12px;letter-spacing:-.01em}
+ p{color:#aaa;line-height:1.6;margin:0 0 16px;font-size:15px}
+ .btn{display:inline-block;padding:12px 24px;background:linear-gradient(135deg,#6a5cff,#ff5ca8);color:#fff;text-decoration:none;border-radius:10px;font-weight:600;font-size:15px;margin:8px 0 20px}
+ .code{font-family:monospace;font-size:32px;letter-spacing:.15em;color:#fff;background:#0f0f17;border:1px solid #2a2a36;border-radius:8px;padding:12px 20px;display:inline-block;margin:8px 0 20px}
+ .muted{color:#555;font-size:13px}
+ hr{border:none;border-top:1px solid #2a2a36;margin:24px 0}
+</style></head>
+<body><div class="card">${body}</div></body></html>`;
+}
+
+function welcomeHtml(name) {
+ return layout(`
+ <p class="brand">3D Agent</p>
+ <h1>Welcome, ${esc(name)} 👋</h1>
+ <p>Your account is ready. Start by uploading your first 3D avatar or connecting an on-chain agent identity.</p>
+ <a class="btn" href="${APP_URL}/dashboard/">Open Dashboard</a>
+ <hr>
+ <p class="muted">Questions? Reply to this email and we'll help you out.</p>
+ `);
+}
+
+function welcomeText(name) {
+ return `Welcome to 3D Agent, ${name}!\n\nYour account is ready. Open your dashboard: ${APP_URL}/dashboard/\n\nQuestions? Reply to this email.`;
+}
+
+function verifyHtml(code, mins) {
+ return layout(`
+ <p class="brand">3D Agent</p>
+ <h1>Verify your email</h1>
+ <p>Enter this code to verify your email address. It expires in ${mins} minutes.</p>
+ <div class="code">${esc(code)}</div>
+ <p class="muted">If you didn't request this, you can ignore it.</p>
+ `);
+}
+
+function verifyText(code, mins) {
+ return `Your 3D Agent verification code is: ${code}\n\nExpires in ${mins} minutes.`;
+}
+
+function resetHtml(url, mins) {
+ return layout(`
+ <p class="brand">3D Agent</p>
+ <h1>Reset your password</h1>
+ <p>Click below to set a new password. This link expires in ${mins} minutes.</p>
+ <a class="btn" href="${esc(url)}">Reset password</a>
+ <p class="muted">If you didn't request a reset, you can safely ignore this email.</p>
+ `);
+}
+
+function resetText(url, mins) {
+ return `Reset your 3D Agent password:\n${url}\n\nExpires in ${mins} minutes.`;
+}
+
+function subscriptionHtml(plan, chain, txId) {
+ return layout(`
+ <p class="brand">3D Agent</p>
+ <h1>${capitalize(plan)} plan activated 🎉</h1>
+ <p>Your <strong>${capitalize(plan)}</strong> subscription is now active on ${capitalize(chain)}.</p>
+ ${txId ? `<p class="muted">Transaction: <code>${esc(txId)}</code></p>` : ''}
+ <a class="btn" href="${APP_URL}/dashboard/">Go to Dashboard</a>
+ `);
+}
+
+function subscriptionText(plan, chain, txId) {
+ return `Your 3D Agent ${plan} plan is now active on ${chain}.\n${txId ? `Transaction: ${txId}\n` : ''}Open dashboard: ${APP_URL}/dashboard/`;
+}
+
+function esc(s) {
+ return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
+}
+function capitalize(s) { return s ? s[0].toUpperCase() + s.slice(1) : s; }
diff --git a/api/auth/siwe/verify.js b/api/auth/siwe/verify.js
index bc10d9e8e..b51279036 100644
--- a/api/auth/siwe/verify.js
+++ b/api/auth/siwe/verify.js
@@ -10,6 +10,7 @@ import { limits, clientIp } from '../../_lib/rate-limit.js';
import { env } from '../../_lib/env.js';
import { parse } from '../../_lib/validate.js';
import { hmacSha256, constantTimeEquals } from '../../_lib/crypto.js';
+import { sendWelcomeEmail } from '../../_lib/email.js';
const verifyBody = z.object({
message: z.string().min(64).max(4000),
diff --git a/home.css b/home.css
index 9a24fd987..02369d653 100644
--- a/home.css
+++ b/home.css
@@ -124,6 +124,22 @@
pointer-events: auto;
}
+/* ── Scroll-driven float on the avatar column ───────────────────────────── */
+
+@supports (animation-timeline: scroll()) {
+ .h-hero-visual {
+ animation: hero-visual-float linear both;
+ animation-timeline: scroll(nearest);
+ animation-range: 0vh 160vh;
+ }
+
+ @keyframes hero-visual-float {
+ 0% { transform: translateY(0) scale(1); }
+ 60% { transform: translateY(-28px) scale(1.02); }
+ 100% { transform: translateY(-60px) scale(0.96); opacity: 0.4; }
+ }
+}
+
/* ── Flat sections below hero need explicit bg to cover star layer ───────── */
.home-parallax .h-section,
diff --git a/home.html b/home.html
index 218c837eb..2b9f17a0a 100644
--- a/home.html
+++ b/home.html
@@ -374,6 +374,38 @@
});
})();
+ // Scroll-driven avatar orbit
+ (function () {
+ const scrollEl = document.querySelector('.home-parallax');
+ const mv = document.querySelector('.h-avatar-viewer');
+ const heroAct = document.querySelector('.h-hero-act');
+ if (!scrollEl || !mv || !heroAct) return;
+
+ // Disable auto-rotate — scroll drives the camera instead
+ mv.removeAttribute('auto-rotate');
+
+ const startOrbit = { theta: 20, phi: 68, r: 3.4 };
+ const endOrbit = { theta: 300, phi: 62, r: 4.0 };
+
+ function lerp(a, b, t) { return a + (b - a) * t; }
+ function ease(t) { return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t; }
+
+ let ticking = false;
+ scrollEl.addEventListener('scroll', function () {
+ if (ticking) return;
+ ticking = true;
+ requestAnimationFrame(function () {
+ const progress = Math.min(scrollEl.scrollTop / heroAct.offsetHeight, 1);
+ const t = ease(progress);
+ const theta = lerp(startOrbit.theta, endOrbit.theta, t);
+ const phi = lerp(startOrbit.phi, endOrbit.phi, t);
+ const r = lerp(startOrbit.r, endOrbit.r, t);
+ mv.setAttribute('camera-orbit', theta.toFixed(1) + 'deg ' + phi.toFixed(1) + 'deg ' + r.toFixed(2) + 'm');
+ ticking = false;
+ });
+ }, { passive: true });
+ })();
+
// Star field canvas
(function () {
for (const canvas of document.querySelectorAll('[data-role="star-canvas"]')) {
diff --git a/public/wallet-login.js b/public/wallet-login.js
index 7bfbf64d5..caa604d9d 100644
--- a/public/wallet-login.js
+++ b/public/wallet-login.js
@@ -1,10 +1,11 @@
-// Client-side wallet authentication (SIWE / MetaMask).
+// Client-side wallet authentication for both EVM (SIWE) and Solana (SIWS).
// Loaded as a module from login.html — imports from CDN so it works outside Vite.
import { createConnectWalletButton } from '/wallet/connect-button.js';
+import { createSolanaWalletButton } from '/wallet/connect-button-solana.js';
const params = new URLSearchParams(location.search);
-const next = params.get('next') || '/dashboard/';
+const next = params.get('next') || '/dashboard/';
function setErr(m) {
const el = document.getElementById('err');
@@ -15,19 +16,22 @@ function clearErr() {
if (el) el.style.display = 'none';
}
-const walletMount = document.getElementById('wallet-mount');
-if (walletMount) {
- const ctrl = createConnectWalletButton(walletMount, {
+function onSuccess() {
+ try {
+ localStorage.setItem('3dagent:auth-hint', JSON.stringify({ authed: true, ts: Date.now() }));
+ } catch { /* ignore */ }
+ location.href = next;
+}
+
+// ─── EVM wallet button ────────────────────────────────────────────────────────
+
+const evmMount = document.getElementById('wallet-mount');
+if (evmMount) {
+ const evmCtrl = createConnectWalletButton(evmMount, {
verifyUrl: '/api/auth/siwe/verify',
- onSuccess: () => {
- try {
- localStorage.setItem('3dagent:auth-hint', JSON.stringify({ authed: true, ts: Date.now() }));
- } catch { /* ignore */ }
- location.href = next;
- },
+ onSuccess,
});
-
- ctrl.addEventListener('change', (e) => {
+ evmCtrl.addEventListener('change', (e) => {
const { status, error } = e.detail;
if (status === 'error') {
const msg = error?.message || 'Sign in failed.';
@@ -36,4 +40,52 @@ if (walletMount) {
clearErr();
}
});
-}
\ No newline at end of file
+}
+
+// ─── Solana wallet button ─────────────────────────────────────────────────────
+
+let solanaCtrl = null;
+
+function mountSolanaButton(preferredWallet = null) {
+ const mount = document.getElementById('solana-wallet-mount');
+ if (!mount) return;
+ if (solanaCtrl) solanaCtrl.disconnect();
+
+ solanaCtrl = createSolanaWalletButton(mount, {
+ preferredWallet,
+ verifyUrl: '/api/auth/siws/verify',
+ onSuccess,
+ });
+ solanaCtrl.addEventListener('change', (e) => {
+ const { status, error } = e.detail;
+ if (status === 'error') {
+ setErr(error?.message || 'Sign in failed.');
+ } else {
+ clearErr();
+ }
+ });
+}
+
+mountSolanaButton();
+
+// Wallet hint buttons (Phantom / Backpack / Solflare)
+document.querySelectorAll('.wallet-hint-btn').forEach((btn) => {
+ btn.addEventListener('click', () => {
+ document.querySelectorAll('.wallet-hint-btn').forEach((b) => b.classList.remove('active'));
+ btn.classList.add('active');
+ mountSolanaButton(btn.dataset.wallet);
+ });
+});
+
+// ─── Chain tab switcher ───────────────────────────────────────────────────────
+
+document.querySelectorAll('.chain-tab').forEach((tab) => {
+ tab.addEventListener('click', () => {
+ const chain = tab.dataset.chain;
+ document.querySelectorAll('.chain-tab').forEach((t) => t.classList.remove('active'));
+ document.querySelectorAll('.chain-panel').forEach((p) => p.classList.remove('active'));
+ tab.classList.add('active');
+ document.getElementById(`${chain}-panel`)?.classList.add('active');
+ clearErr();
+ });
+});