Skip to content

Commit dce7d36

Browse files
committed
feat: Implement singleton pattern for Supabase client instance
1 parent 742a5cc commit dce7d36

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ui/src/lib/supabase/client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { createClient as createSupabaseClient } from "@supabase/supabase-js";
22

3+
// シングルトンインスタンス
4+
let supabaseInstance: ReturnType<typeof createSupabaseClient> | null = null;
5+
36
export function createClient() {
4-
return createSupabaseClient(
7+
// 既にインスタンスが存在する場合はそれを返す
8+
if (supabaseInstance) {
9+
return supabaseInstance;
10+
}
11+
12+
// 新しいインスタンスを作成
13+
supabaseInstance = createSupabaseClient(
514
// @ts-ignore: TS2339
615
import.meta.env.VITE_SUPABASE_URL!,
716
// @ts-ignore: TS2339
817
import.meta.env.VITE_SUPABASE_ANON_KEY!,
918
);
19+
20+
return supabaseInstance;
1021
}

0 commit comments

Comments
 (0)