mirror of
https://github.com/Luchexx/wacrm.git
synced 2026-11-02 09:19:51 +00:00
Merge pull request #2 from ArnasDon/fix/supabase-client-singleton
Fix auth lock contention and empty error logs (runtime errors)
This commit is contained in:
commit
b9647822ff
@ -54,7 +54,13 @@ export function ConversationList({
|
||||
.order("last_message_at", { ascending: false });
|
||||
|
||||
if (error) {
|
||||
console.error("Failed to fetch conversations:", error);
|
||||
// Supabase errors have non-enumerable properties — log fields explicitly
|
||||
console.error("Failed to fetch conversations:", {
|
||||
message: error.message,
|
||||
details: error.details,
|
||||
hint: error.hint,
|
||||
code: error.code,
|
||||
});
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,8 +1,18 @@
|
||||
import { createBrowserClient } from '@supabase/ssr'
|
||||
import type { SupabaseClient } from '@supabase/supabase-js'
|
||||
|
||||
// Singleton instance — one client shared across the whole browser session.
|
||||
// Creating multiple clients causes auth-lock contention ("Lock was released
|
||||
// because another request stole it") and intermittent fetch failures.
|
||||
let browserClient: SupabaseClient | undefined
|
||||
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
if (browserClient) return browserClient
|
||||
|
||||
browserClient = createBrowserClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
)
|
||||
|
||||
return browserClient
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user