Spaces:
Running

microfunnel-api / backend /app /core /supabase.py
axeronis
Fix: Telegram notification bugs - add missing token parameter
01bc36c
Raw History Blame Contribute Delete
848 Bytes
from supabase import create_client, Client
from app.core.config import settings
def get_supabase_client() -> Client:
"""
Get or create Supabase client.
Prefers SERVICE_KEY (bypasses RLS) over regular KEY.
"""
if not settings.SUPABASE_URL:
raise RuntimeError("SUPABASE_URL not configured")
# Use service key if available (bypasses RLS policies)
# Otherwise fallback to regular key for backward compatibility
api_key = settings.SUPABASE_SERVICE_KEY or settings.SUPABASE_KEY
if not api_key:
raise RuntimeError("SUPABASE_KEY or SUPABASE_SERVICE_KEY required")
return create_client(settings.SUPABASE_URL, api_key)
# Global accessibility
supabase_client = get_supabase_client() if (settings.SUPABASE_URL and (settings.SUPABASE_SERVICE_KEY or settings.SUPABASE_KEY)) else None