Spaces:
Sleeping

File size: 848 Bytes
0f84c85
 
 
 
 
 
 
01bc36c
0f84c85
01bc36c
 
 
 
 
 
 
 
 
0f84c85
01bc36c
0f84c85
 
01bc36c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

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