This commit is contained in:
hailin 2025-05-20 19:43:18 +08:00
parent 3b540f2c6e
commit f6b8dcbf84
1 changed files with 8 additions and 7 deletions

View File

@ -49,12 +49,15 @@ let _supabase: ReturnType<typeof createBrowserClient<Database>> | null = null;
// 创建 Supabase 客户端的工厂方法
export async function createClient() {
if (_supabase) return _supabase; // 如果已经创建过客户端,直接返回
// 如果已经创建过客户端,直接返回
if (_supabase) return _supabase;
const url = await getRuntimeSupabaseUrl(); // 获取动态的 SUPABASE_URL
// 获取动态的 SUPABASE_URL
const url = await getRuntimeSupabaseUrl();
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!; // 写死的 anon key
_supabase = createBrowserClient(url, key); // 创建并缓存 Supabase 客户端实例
// 创建并缓存 Supabase 客户端实例
_supabase = createBrowserClient(url, key);
return _supabase;
}
@ -68,7 +71,5 @@ async function getRuntimeSupabaseUrl(retry = 30, interval = 50): Promise<string>
throw new Error("RUNTIME_ENV.SUPABASE_URL not ready");
}
// 返回客户端实例
export const supabase = async () => {
return await createClient(); // 返回创建好的 Supabase 客户端
};
// 确保返回的 supabase 实例兼容原有的代码
export const supabase = createClient; // 保持原有方式调用 supabase