fix(auth): replace navigator.locks with in-process serial lock to avoid 'lock stolen' aborts
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "ChatApp",
|
"productName": "ChatApp",
|
||||||
"version": "0.3.6",
|
"version": "0.3.7",
|
||||||
"identifier": "com.meinname.chatapp",
|
"identifier": "com.meinname.chatapp",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm vite:dev",
|
"beforeDevCommand": "pnpm vite:dev",
|
||||||
|
|||||||
@@ -5,6 +5,20 @@ import type { Database, SupabaseConfig } from './types.js';
|
|||||||
// Typed client alias used throughout the app.
|
// Typed client alias used throughout the app.
|
||||||
export type AppSupabaseClient = SupabaseClient<Database>;
|
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 {
|
export function createClient(config: SupabaseConfig): AppSupabaseClient {
|
||||||
return createSupabaseClient<Database>(config.url, config.anonKey, {
|
return createSupabaseClient<Database>(config.url, config.anonKey, {
|
||||||
auth: {
|
auth: {
|
||||||
@@ -12,6 +26,7 @@ export function createClient(config: SupabaseConfig): AppSupabaseClient {
|
|||||||
autoRefreshToken: true,
|
autoRefreshToken: true,
|
||||||
persistSession: true,
|
persistSession: true,
|
||||||
detectSessionInUrl: config.detectSessionInUrl ?? false,
|
detectSessionInUrl: config.detectSessionInUrl ?? false,
|
||||||
|
lock: acquireLock,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user