17 lines
733 B
TypeScript
17 lines
733 B
TypeScript
import { createClient } from '@supabase/supabase-js';
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
const supabaseUrl = process.env.SUPABASE_URL;
|
|
// We use the service role key in the backend to bypass RLS when necessary (e.g. inserting system analyses),
|
|
// or we can use anon key if RLS allows it. Let's assume we use the anon key or service role key provided in ENV.
|
|
// However, the frontend passes the user_id, so the backend can act on behalf of the user.
|
|
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_ANON_KEY;
|
|
|
|
if (!supabaseUrl || !supabaseKey) {
|
|
throw new Error('Missing Supabase URL or Key in environment variables');
|
|
}
|
|
|
|
export const supabase = createClient(supabaseUrl, supabaseKey);
|