Files
ChatApp/packages/shared/src/supabase/client.ts
T
byGalax b61f929cf7 fix(shared): drop .js extensions from relative imports for Metro
packages/shared/src/index.ts and all sub-modules used .js extensions on
relative imports (e.g. './admin/index.js') pointing at .ts source files.
TypeScript with moduleResolution: "Bundler" doesn't need them, and
Metro's eager exporter (used for preview / production builds) reads
them literally and fails — only the dev-server Metro fell back to .ts.

Workspace typecheck remains 8/8 green; Vite and TS Bundler resolution
already accept both styles, so desktop is unaffected.
2026-05-15 01:52:14 +02:00

33 lines
1.3 KiB
TypeScript

import { createClient as createSupabaseClient, type SupabaseClient } from '@supabase/supabase-js';
import type { Database, SupabaseConfig } from './types';
// Typed client alias used throughout the app.
export type AppSupabaseClient = SupabaseClient<Database>;
// Inline serial lock — replaces Supabase's default `navigator.locks` based
// lock that occasionally throws "Lock was stolen by another request" when
// the same origin opens multiple tabs / Tauri windows / HMR-reloaded
// modules. We only have one client instance per process so a simple promise
// chain serialises token-refresh fine without cross-tab coordination.
const acquireLock = (() => {
let chain: Promise<unknown> = Promise.resolve();
return async <R>(_name: string, _acquireTimeout: number, fn: () => Promise<R>): Promise<R> => {
const next = chain.then(() => fn(), () => fn());
chain = next.catch(() => undefined);
return next;
};
})();
export function createClient(config: SupabaseConfig): AppSupabaseClient {
return createSupabaseClient<Database>(config.url, config.anonKey, {
auth: {
storage: config.sessionStorage,
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: config.detectSessionInUrl ?? false,
lock: acquireLock,
},
});
}