From ea6c1f1bbef42e150d304bc481aa5cbd8f7fb454 Mon Sep 17 00:00:00 2001 From: clockwork-labs-bot Date: Sun, 15 Feb 2026 17:20:57 -0500 Subject: [PATCH] Store auth tokens per server/database in localStorage Use a localStorage key that includes the server URI and database name (`${HOST}/${DB_NAME}/auth_token`) so that different servers and modules don't overwrite each other's tokens. Applied to all templates (react, vue, svelte, nuxt, nextjs, remix, tanstack, chat-react) and updated docs (tutorial, quickstarts, connection reference). Also fixes withModuleName -> withDatabaseName in nuxt, nextjs, remix, and tanstack templates. Closes #3252 --- .../docs/00100-intro/00200-quickstarts/00155-nuxt.md | 7 ++++--- .../00100-intro/00200-quickstarts/00180-browser.md | 12 ++++++++---- .../00100-intro/00300-tutorials/00100-chat-app.md | 12 ++++++++---- .../00600-client-sdk-languages/00300-connection.md | 12 ++++++++---- templates/chat-react-ts/src/App.integration.test.tsx | 6 +++++- templates/chat-react-ts/src/main.tsx | 5 +++-- templates/nextjs-ts/app/providers.tsx | 7 ++++--- templates/nuxt-ts/app.vue | 7 ++++--- templates/react-ts/src/main.tsx | 5 +++-- templates/remix-ts/app/root.tsx | 7 ++++--- templates/svelte-ts/src/Root.svelte | 5 +++-- templates/tanstack-ts/src/router.tsx | 7 ++++--- templates/vue-ts/src/main.ts | 5 +++-- 13 files changed, 61 insertions(+), 36 deletions(-) diff --git a/docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md b/docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md index 1dc8e7dadf8..dc8065d68fe 100644 --- a/docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md +++ b/docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md @@ -185,14 +185,15 @@ import { DbConnection } from './module_bindings'; const HOST = import.meta.env.VITE_SPACETIMEDB_HOST ?? 'ws://localhost:3000'; const DB_NAME = import.meta.env.VITE_SPACETIMEDB_DB_NAME ?? 'nuxt-ts'; +const TOKEN_KEY = `${HOST}/${DB_NAME}/auth_token`; const connectionBuilder = import.meta.client ? DbConnection.builder() .withUri(HOST) - .withModuleName(DB_NAME) - .withToken(localStorage.getItem('auth_token') || undefined) + .withDatabaseName(DB_NAME) + .withToken(localStorage.getItem(TOKEN_KEY) || undefined) .onConnect((_conn, identity, token) => { - localStorage.setItem('auth_token', token); + localStorage.setItem(TOKEN_KEY, token); console.log('Connected:', identity.toHexString()); }) .onDisconnect(() => console.log('Disconnected')) diff --git a/docs/docs/00100-intro/00200-quickstarts/00180-browser.md b/docs/docs/00100-intro/00200-quickstarts/00180-browser.md index bf46e58012f..649f7e2eaba 100644 --- a/docs/docs/00100-intro/00200-quickstarts/00180-browser.md +++ b/docs/docs/00100-intro/00200-quickstarts/00180-browser.md @@ -63,12 +63,16 @@ npm run build