Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Use the canonical Edge Functions admin key first, keep SB_SECRET_KEY as fallback.

Anibal Svarcase5cfc4cf1141
diff --git a/supabase/functions/_shared/supabaseAdmin.ts b/supabase/functions/_shared/supabaseAdmin.ts
index 72b26943..b440e700 100644
--- a/supabase/functions/_shared/supabaseAdmin.ts
+++ b/supabase/functions/_shared/supabaseAdmin.ts
@@ -1,9 +1,18 @@
import type { SupabaseClient } from "jsr:@supabase/supabase-js@2";
import { createClient } from "jsr:@supabase/supabase-js@2";
+const supabaseUrl = Deno.env.get("SUPABASE_URL") ?? "";
+const supabaseServiceRoleKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? "";
+const sbSecretKey = Deno.env.get("SB_SECRET_KEY") ?? "";
+const adminKey = supabaseServiceRoleKey || sbSecretKey;
+
+if (!supabaseUrl || !adminKey) {
+ throw new Error("Missing SUPABASE_URL or admin key");
+}
+
export const supabaseAdmin: SupabaseClient = createClient(
- Deno.env.get("SUPABASE_URL") ?? "",
- Deno.env.get("SB_SECRET_KEY") ?? "",
+ supabaseUrl,
+ adminKey,
{
auth: {
autoRefreshToken: false,