"""Supabase client configuration for dashboard analytics.""" import logging import os from functools import lru_cache from supabase import Client, create_client logger = logging.getLogger(__name__) @lru_cache(maxsize=1) def get_supabase_client() -> Client | None: """ Get a cached Supabase client instance. Returns: Supabase client or None if not configured. """ url = os.getenv("SUPABASE_URL") key = os.getenv("SUPABASE_KEY") if not url or not key: logger.warning("Supabase not configured: SUPABASE_URL or SUPABASE_KEY missing") return None try: client = create_client(url, key) logger.info("Supabase client initialized successfully") return client except Exception as e: logger.error(f"Failed to initialize Supabase client: {e}") return None