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: enhance user account handling in SIWE/SIWS verification and improve dashboard wallet loading

nirholas477745be3a38
diff --git a/api/auth/siwe/verify.js b/api/auth/siwe/verify.js
index b5b420367..09adf5a41 100644
--- a/api/auth/siwe/verify.js
+++ b/api/auth/siwe/verify.js
@@ -146,8 +146,9 @@ export default wrap(async (req, res) => {
// before user_wallets existed, or by a different flow that only set the
// users column. Reconcile by backfilling user_wallets.
const placeholderEmail = `wallet-${addrLower}@wallet.local`;
- // Include soft-deleted rows so we can reject them with a clear error
- // instead of colliding on the email unique constraint.
+ // Include soft-deleted rows so we don't collide on the email unique
+ // constraint. Re-signing-in with the same wallet restores the account —
+ // the placeholder email is wallet-derived, so SIWE proves ownership.
const [existingUser] = await sql`
select id, deleted_at from users
where wallet_address = ${addrLower} or email = ${placeholderEmail}
@@ -155,18 +156,13 @@ export default wrap(async (req, res) => {
`;
if (existingUser) {
- if (existingUser.deleted_at) {
- return error(
- res,
- 403,
- 'account_deleted',
- 'this wallet is linked to a deleted account',
- );
- }
userId = existingUser.id;
await sql`
- update users set wallet_address = ${addrLower}
- where id = ${userId} and wallet_address is distinct from ${addrLower}
+ update users
+ set wallet_address = ${addrLower},
+ deleted_at = null
+ where id = ${userId}
+ and (wallet_address is distinct from ${addrLower} or deleted_at is not null)
`;
await sql`
insert into user_wallets (user_id, address, chain_id, is_primary)
@@ -183,7 +179,8 @@ export default wrap(async (req, res) => {
insert into users (email, display_name, wallet_address)
values (${placeholderEmail}, ${shortAddr(claimed)}, ${addrLower})
on conflict (email) do update
- set wallet_address = ${addrLower}
+ set wallet_address = ${addrLower},
+ deleted_at = null
returning id, (xmax = 0) as inserted
`;
userId = user.id;
diff --git a/api/auth/siws/verify.js b/api/auth/siws/verify.js
index 220a53d2c..1517bb34f 100644
--- a/api/auth/siws/verify.js
+++ b/api/auth/siws/verify.js
@@ -136,17 +136,48 @@ export default wrap(async (req, res) => {
`;
} else {
const placeholderEmail = `sol-${addr.slice(0, 8).toLowerCase()}@wallet.local`;
- const [user] = await sql`
- insert into users (email, display_name)
- values (${placeholderEmail}, ${shortAddr(addr)})
- returning id
+ const [existingUser] = await sql`
+ select id, deleted_at from users
+ where email = ${placeholderEmail}
+ limit 1
`;
- userId = user.id;
- await sql`
- insert into user_wallets (user_id, address, chain_type, is_primary)
- values (${userId}, ${addr}, 'solana', true)
- `;
- queueMicrotask(() => sendWelcomeEmail({ to: placeholderEmail, displayName: shortAddr(addr) }));
+
+ if (existingUser) {
+ if (existingUser.deleted_at) {
+ return error(
+ res,
+ 403,
+ 'account_deleted',
+ 'this wallet is linked to a deleted account',
+ );
+ }
+ userId = existingUser.id;
+ await sql`
+ insert into user_wallets (user_id, address, chain_type, is_primary)
+ values (${userId}, ${addr}, 'solana', true)
+ on conflict (address) do update
+ set last_used_at = now()
+ `;
+ } else {
+ const [user] = await sql`
+ insert into users (email, display_name)
+ values (${placeholderEmail}, ${shortAddr(addr)})
+ on conflict (email) do update set email = excluded.email
+ returning id, (xmax = 0) as inserted
+ `;
+ userId = user.id;
+ await sql`
+ insert into user_wallets (user_id, address, chain_type, is_primary)
+ values (${userId}, ${addr}, 'solana', true)
+ on conflict (address) do update
+ set last_used_at = now()
+ `;
+ if (user.inserted) {
+ queueMicrotask(() =>
+ sendWelcomeEmail({ to: placeholderEmail, displayName: shortAddr(addr) }),
+ );
+ }
+ }
}
// 8. Issue session.
diff --git a/public/dashboard/dashboard.js b/public/dashboard/dashboard.js
index f6eab1029..e527b769e 100644
--- a/public/dashboard/dashboard.js
+++ b/public/dashboard/dashboard.js
@@ -1,17 +1,7 @@
// Dashboard single-file app. Uses native DOM — no framework.
// Keeps bundle small and ensures anything rendering <model-viewer> works without bundler.
-// Lazy: /src/ isn't on the production static surface, so a top-level import here
-// would 404 and break every tab. Resolve on first use, swallow failures.
-let _solanaWalletPromise = null;
-function loadSolanaWalletCard() {
- if (!_solanaWalletPromise) {
- _solanaWalletPromise = import('/src/agent-solana-wallet.js')
- .then((m) => m.mountAgentSolanaWalletCard)
- .catch(() => null);
- }
- return _solanaWalletPromise;
-}
+import { mountAgentSolanaWalletCard } from '/src/agent-solana-wallet.js';
export const state = { user: null };
@@ -237,12 +227,9 @@ function mountAvatarWalletSection(host, a) {
} catch {}
});
}
- loadSolanaWalletCard().then((mount) => {
- if (!mount) return;
- mount({
- panel: host.querySelector('[data-sol-wallet]'),
- identity: { id: a.agent_id, name: a.name },
- });
+ mountAgentSolanaWalletCard({
+ panel: host.querySelector('[data-sol-wallet]'),
+ identity: { id: a.agent_id, name: a.name },
});
}
diff --git a/public/login.html b/public/login.html
index a1daf4dd5..5ebd77f5e 100644
--- a/public/login.html
+++ b/public/login.html
@@ -785,6 +785,7 @@
const next =
params.get('next') || sessionStorage.getItem('login_redirect') || '/create';
sessionStorage.removeItem('login_redirect');
+ window.__loginNext = next;
const navType = performance.getEntriesByType('navigation')[0]?.type;
if (navType !== 'back_forward') {
fetch('/api/auth/me', { credentials: 'include' })
diff --git a/public/register.html b/public/register.html
index 9902fca15..b5c371d1c 100644
--- a/public/register.html
+++ b/public/register.html
@@ -600,6 +600,7 @@
const params = new URLSearchParams(location.search);
const next = params.get('next') || sessionStorage.getItem('login_redirect') || '/create';
sessionStorage.removeItem('login_redirect');
+ window.__loginNext = next;
const form = document.getElementById('f');
const err = document.getElementById('err');
const btn = document.getElementById('submit');
diff --git a/public/wallet-login.js b/public/wallet-login.js
index 06c67baf6..bd93cba86 100644
--- a/public/wallet-login.js
+++ b/public/wallet-login.js
@@ -5,7 +5,7 @@ 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') || sessionStorage.getItem('login_redirect') || '/dashboard/';
+const next = window.__loginNext || params.get('next') || sessionStorage.getItem('login_redirect') || '/create';
sessionStorage.removeItem('login_redirect');
function setErr(m) {
diff --git a/vite.config.js b/vite.config.js
index 7a552446e..4aed988e7 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -176,6 +176,18 @@ const appConfig = {
});
},
},
+ {
+ // Several static pages (dashboard, vanity-wallet, …) import ESM
+ // directly from `/src/*.js`. Vite's dev server serves these from
+ // the project root, but production needs them under dist/. Mirror
+ // the tree so the runtime URLs resolve.
+ name: 'copy-src-to-dist',
+ closeBundle() {
+ cpSync(resolve(__dirname, 'src'), resolve(__dirname, 'dist/src'), {
+ recursive: true,
+ });
+ },
+ },
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'pwa-192x192.png', 'pwa-512x512.png', 'pwa-icon.svg'],