Spaces:
Sleeping
Sleeping
Fix TypeScript compilation types for Supabase proxy wrapper
Browse files
algospaced-ui/src/supabaseClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
import { createClient } from '@supabase/supabase-js';
|
| 2 |
|
| 3 |
-
let supabaseInstance:
|
| 4 |
|
| 5 |
export function initializeSupabase(url: string, key: string) {
|
| 6 |
if (url && key) {
|
|
@@ -10,7 +10,7 @@ export function initializeSupabase(url: string, key: string) {
|
|
| 10 |
|
| 11 |
// Proxy wrapper that delegates all calls to the dynamically initialized instance
|
| 12 |
export const supabase = new Proxy({} as any, {
|
| 13 |
-
get(
|
| 14 |
if (!supabaseInstance) {
|
| 15 |
// Fallback: try loading from build-time environment if not initialized yet
|
| 16 |
const url = import.meta.env.VITE_SUPABASE_URL || '';
|
|
@@ -21,7 +21,8 @@ export const supabase = new Proxy({} as any, {
|
|
| 21 |
throw new Error("Supabase client is not initialized. Please call initializeSupabase(url, key) first.");
|
| 22 |
}
|
| 23 |
}
|
| 24 |
-
return supabaseInstance[prop];
|
| 25 |
}
|
| 26 |
-
});
|
|
|
|
| 27 |
|
|
|
|
| 1 |
+
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
| 2 |
|
| 3 |
+
let supabaseInstance: SupabaseClient | null = null;
|
| 4 |
|
| 5 |
export function initializeSupabase(url: string, key: string) {
|
| 6 |
if (url && key) {
|
|
|
|
| 10 |
|
| 11 |
// Proxy wrapper that delegates all calls to the dynamically initialized instance
|
| 12 |
export const supabase = new Proxy({} as any, {
|
| 13 |
+
get(_target, prop) {
|
| 14 |
if (!supabaseInstance) {
|
| 15 |
// Fallback: try loading from build-time environment if not initialized yet
|
| 16 |
const url = import.meta.env.VITE_SUPABASE_URL || '';
|
|
|
|
| 21 |
throw new Error("Supabase client is not initialized. Please call initializeSupabase(url, key) first.");
|
| 22 |
}
|
| 23 |
}
|
| 24 |
+
return (supabaseInstance as any)[prop];
|
| 25 |
}
|
| 26 |
+
}) as unknown as SupabaseClient;
|
| 27 |
+
|
| 28 |
|