feat(tlsync): fetch short-lived token from API before multiplayer connect
app-ci-deploy / test-build-deploy (push) Has been cancelled

- Remove VITE_TLSYNC_SECRET from browser env (no longer exposed to bundle)
- Add useTlsyncToken hook that fetches /api/tlsync/token with Supabase auth
- Extract TldrawCanvas sub-component: only renders after token is ready
- Pass API-issued short-lived token to createSyncConnectionOptions
- Add vite.config.ts blocklist to prevent secret leak (defense-in-depth)
- Remove VITE_TLSYNC_SECRET from .env.example (server-side only now)

Related: t_a69128a1 (API token endpoint), t_41a844a7 (this task)
This commit is contained in:
2026-05-28 18:00:43 +01:00
parent 0db53bfd9c
commit 67e47fc47f
4 changed files with 161 additions and 80 deletions
+3 -1
View File
@@ -14,9 +14,11 @@ export default defineConfig(({ mode }) => {
// Determine client-side env vars to expose
const envPrefix = 'VITE_'
// Defense-in-depth: never expose server-only secrets to the browser bundle
const envBlocklist = new Set(['VITE_TLSYNC_SECRET'])
const clientEnv = Object.fromEntries(
Object.entries(env)
.filter(([key]) => key.startsWith(envPrefix))
.filter(([key]) => key.startsWith(envPrefix) && !envBlocklist.has(key))
.map(([key, value]) => [`import.meta.env.${key}`, JSON.stringify(value)])
)