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 session management for login redirection and enhance authentication flow

nirholasd50495071dc9
diff --git a/create.html b/create.html
index 9bc0b4743..68759d5e3 100644
--- a/create.html
+++ b/create.html
@@ -410,6 +410,14 @@
}
}
</style>
+ <script>
+ fetch('/api/auth/me', { credentials: 'include' }).then(function(r) {
+ if (!r.ok) {
+ sessionStorage.setItem('login_redirect', '/create');
+ location.replace('/login');
+ }
+ });
+ </script>
</head>
<body>
<header class="topbar">
diff --git a/public/login.html b/public/login.html
index 56ea7b494..3dcd7e992 100644
--- a/public/login.html
+++ b/public/login.html
@@ -154,7 +154,8 @@
<script type="module" src="/wallet-login.js"></script>
<script>
const params = new URLSearchParams(location.search);
- const next = params.get('next') || '/dashboard/';
+ const next = params.get('next') || sessionStorage.getItem('login_redirect') || '/dashboard/';
+ sessionStorage.removeItem('login_redirect');
// If already signed in, skip the login form entirely.
fetch('/api/auth/me', { credentials: 'include' })
diff --git a/src/app.js b/src/app.js
index fb0120d97..35bed8b5d 100644
--- a/src/app.js
+++ b/src/app.js
@@ -408,10 +408,11 @@ class App {
else if (deploy) mode = 'deploy';
document.body.dataset.viewerMode = mode;
if (mode === 'main') {
- // Use 'false' hint immediately to skip auth-gate flash for known-logged-out users.
- // Never use 'true' hint optimistically — a stale hint would show then snap-hide the
- // sidebar once /api/auth/me confirms the session expired.
- document.body.dataset.authed = readAuthHint() === 'false' ? 'false' : 'pending';
+ // Only use 'pending' (hide gate, hide sidebar) when we have a stored 'true' hint —
+ // i.e. the user was last seen logged in and may still be. For everyone else (no hint
+ // or a 'false' hint) show the auth gate immediately so it never appears after the
+ // CZ model renders (which is instant when the GLB is cached from the homepage).
+ document.body.dataset.authed = readAuthHint() === 'true' ? 'pending' : 'false';
}
}
diff --git a/src/create.js b/src/create.js
index 126c57424..80c8c2372 100644
--- a/src/create.js
+++ b/src/create.js
@@ -4,10 +4,6 @@ import { AvatarCreator } from './avatar-creator.js';
// GLB magic bytes: ASCII "glTF"
const GLB_MAGIC = [0x67, 0x6c, 0x54, 0x46];
-function redirectToLogin() {
- window.location.href = '/login?next=' + encodeURIComponent('/create');
-}
-
async function boot() {
const creator = new AvatarCreator(document.body, (blob) =>
saveAndRedirect(blob, { source: 'avaturn' }),
@@ -72,7 +68,8 @@ async function saveAndRedirect(blob, meta = {}) {
window.location.href = '/agent/' + agent.id;
} catch (err) {
if (err.code === 'not_signed_in') {
- redirectToLogin();
+ sessionStorage.setItem('login_redirect', '/create');
+ window.location.replace('/login');
return;
}
if (!err.redirected) showStatus(err.message || 'Upload failed.', 'error');
diff --git a/vercel.json b/vercel.json
index eb9f30036..9cb204375 100644
--- a/vercel.json
+++ b/vercel.json
@@ -21,13 +21,14 @@
{ "src": "/oauth/revoke", "dest": "/api/oauth/revoke" },
{ "src": "/oauth/introspect", "dest": "/api/oauth/introspect" },
- { "src": "/login", "dest": "/login.html" },
- { "src": "/wallet-login.js", "dest": "/wallet-login.js" },
- { "src": "/wallet/(.*)", "dest": "/wallet/$1" },
+ { "src": "/login", "dest": "/public/login.html" },
+ { "src": "/register", "dest": "/public/register.html" },
+ { "src": "/wallet-login.js", "dest": "/public/wallet-login.js" },
+ { "src": "/wallet/(.*)", "dest": "/public/wallet/$1" },
{ "src": "/deploy", "dest": "/app.html" },
- { "src": "/dashboard", "dest": "/dashboard/index.html" },
- { "src": "/dashboard/", "dest": "/dashboard/index.html" },
- { "src": "/dashboard/(.*)", "dest": "/dashboard/$1" },
+ { "src": "/dashboard", "dest": "/public/dashboard/index.html" },
+ { "src": "/dashboard/", "dest": "/public/dashboard/index.html" },
+ { "src": "/dashboard/(.*)", "dest": "/public/dashboard/$1" },
{ "src": "/hydrate", "dest": "/public/hydrate/index.html" },
{ "src": "/hydrate/", "dest": "/public/hydrate/index.html" },
{ "src": "/studio", "dest": "/public/studio/index.html" },
@@ -47,7 +48,7 @@
"dest": "/api/avatars/[id]/storage-mode?id=$1"
},
{ "src": "/api/avatars/([^/]+)/pin-ipfs", "dest": "/api/avatars/[id]/pin-ipfs?id=$1" },
- { "src": "/dashboard/storage", "dest": "/dashboard/storage.html" },
+ { "src": "/dashboard/storage", "dest": "/public/dashboard/storage.html" },
{
"src": "/api/agents/([^/]+)/embed-policy",
"dest": "/api/agents/[id]/embed-policy?id=$1"
@@ -78,32 +79,32 @@
{ "src": "/api/widgets", "dest": "/api/widgets" },
{ "src": "/api/widgets/([A-Za-z0-9_-]+)", "dest": "/api/widgets/[id]?id=$1" },
{ "src": "/w/([A-Za-z0-9_-]+)", "dest": "/api/widgets/page?id=$1" },
- { "src": "/widgets", "dest": "/widgets-gallery/index.html" },
- { "src": "/widgets/", "dest": "/widgets-gallery/index.html" },
- { "src": "/widgets/(.*)", "dest": "/widgets-gallery/$1" },
- { "src": "/docs/widgets", "dest": "/docs-widgets.html" },
+ { "src": "/widgets", "dest": "/public/widgets-gallery/index.html" },
+ { "src": "/widgets/", "dest": "/public/widgets-gallery/index.html" },
+ { "src": "/widgets/(.*)", "dest": "/public/widgets-gallery/$1" },
+ { "src": "/docs/widgets", "dest": "/public/docs-widgets.html" },
- { "src": "/artifact", "dest": "/artifact/index.html" },
- { "src": "/artifact/", "dest": "/artifact/index.html" },
- { "src": "/artifact/(.*)", "dest": "/artifact/$1" },
+ { "src": "/artifact", "dest": "/public/artifact/index.html" },
+ { "src": "/artifact/", "dest": "/public/artifact/index.html" },
+ { "src": "/artifact/(.*)", "dest": "/public/artifact/$1" },
- { "src": "/cz", "dest": "/cz/index.html" },
- { "src": "/cz/", "dest": "/cz/index.html" },
- { "src": "/cz/(.*)", "dest": "/cz/$1" },
+ { "src": "/cz", "dest": "/public/cz/index.html" },
+ { "src": "/cz/", "dest": "/public/cz/index.html" },
+ { "src": "/cz/(.*)", "dest": "/public/cz/$1" },
- { "src": "/validation", "dest": "/validation/index.html" },
- { "src": "/validation/", "dest": "/validation/index.html" },
- { "src": "/validation/(.*)", "dest": "/validation/$1" },
+ { "src": "/validation", "dest": "/public/validation/index.html" },
+ { "src": "/validation/", "dest": "/public/validation/index.html" },
+ { "src": "/validation/(.*)", "dest": "/public/validation/$1" },
- { "src": "/lobehub/iframe", "dest": "/lobehub/iframe/index.html" },
- { "src": "/lobehub/iframe/", "dest": "/lobehub/iframe/index.html" },
- { "src": "/lobehub/iframe/(.*)", "dest": "/lobehub/iframe/$1" },
+ { "src": "/lobehub/iframe", "dest": "/public/lobehub/iframe/index.html" },
+ { "src": "/lobehub/iframe/", "dest": "/public/lobehub/iframe/index.html" },
+ { "src": "/lobehub/iframe/(.*)", "dest": "/public/lobehub/iframe/$1" },
{ "src": "/api/auth/logout-everywhere", "dest": "/api/auth/logout-everywhere" },
{ "src": "/api/llm/anthropic", "dest": "/api/llm/anthropic.js" },
{ "src": "/api/agents/([^/]+)/usage", "dest": "/api/agents/[id]/usage?id=$1" },
- { "src": "/dashboard/usage", "dest": "/dashboard/usage.html" },
+ { "src": "/dashboard/usage", "dest": "/public/dashboard/usage.html" },
{ "src": "/api/erc8004/hydrate", "dest": "/api/erc8004/hydrate.js" },
{ "src": "/api/erc8004/import", "dest": "/api/erc8004/import.js" },
@@ -154,18 +155,18 @@
{
"src": "/\\.well-known/(.*)",
"headers": { "cache-control": "max-age=86400, public" },
- "dest": "/.well-known/$1"
+ "dest": "/public/.well-known/$1"
},
- { "src": "/robots.txt", "dest": "/robots.txt" },
- { "src": "/sitemap.xml", "dest": "/sitemap.xml" },
+ { "src": "/robots.txt", "dest": "/public/robots.txt" },
+ { "src": "/sitemap.xml", "dest": "/public/sitemap.xml" },
{ "src": "/app", "dest": "/app.html" },
{ "src": "/features", "dest": "/features.html" },
{ "src": "/create", "dest": "/create.html" },
{ "src": "/create/", "dest": "/create.html" },
{ "src": "/home", "dest": "/home.html" },
- { "src": "/explore", "dest": "/explore/index.html" },
- { "src": "/explore/", "dest": "/explore/index.html" },
- { "src": "/explore/(.*)", "dest": "/explore/$1" },
+ { "src": "/explore", "dest": "/public/explore/index.html" },
+ { "src": "/explore/", "dest": "/public/explore/index.html" },
+ { "src": "/explore/(.*)", "dest": "/public/explore/$1" },
{ "src": "/a/(\\d+)/(\\d+)/embed", "dest": "/a-embed.html" },
{ "src": "/a/(\\d+)/(\\d+)", "dest": "/api/a-page?chain=$1&id=$2" },
{ "src": "/a/(.*)", "dest": "/app.html" },