feat(app): optional Supabase connection in runtime config + lazy typed client

- env.ts: supabase: SupabaseConnection | null resolved from env.js
  (supabaseUrl/supabaseAnonKey), VITE_SUPABASE_*, else null; half config refused
- lib/supabase.ts: getSupabaseClient() null when unconfigured, one client per URL
- entrypoint.sh writes the two public values; .env.example placeholders
- Dockerfile copies packages/supabase manifest for the install layer
- no UI change; 7 new tests (278 app)
This commit is contained in:
bchanot committed 2026-10-08 22:43:18 +02:00
1 parent ce76c6597a
commit d239374d81
9 files changed
+153 -23

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { createBrowserClient, type FaunosteoClient } from '@faunosteo/supabase'
import { appConfig, type AppConfig } from '@/config/env'
let cached: { connectionUrl: string; client: FaunosteoClient } | null = null
/**
* Lazily created Supabase client, or null when the deployment has no backend
* configured. Callers must handle null: the current local-only flows do not
* depend on Supabase. No UI uses this yet (foundation step).
*/
export function getSupabaseClient(config: AppConfig = appConfig): FaunosteoClient | null {
if (!config.supabase) return null
if (cached?.connectionUrl !== config.supabase.url) {
cached = {
connectionUrl: config.supabase.url,
client: createBrowserClient(config.supabase),
}
}
return cached.client
}
/** True when the app can talk to Supabase. */
export function isSupabaseConfigured(config: AppConfig = appConfig): boolean {
return config.supabase !== null
}