100kmph/lib/supabase.ts
2025-11-06 00:25:08 +05:30

22 lines
725 B
TypeScript

import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_KEY!;
if (!supabaseUrl || !supabaseKey) {
throw new Error('Missing Supabase environment variables');
}
// Client for public operations (uses anon key)
export const supabase = createClient(supabaseUrl, supabaseKey);
// Admin client for server-side operations (bypasses RLS)
// Use service role key if available, otherwise fallback to anon key
const adminKey = process.env.SUPABASE_SERVICE_ROLE_KEY || supabaseKey;
export const supabaseAdmin = createClient(supabaseUrl, adminKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});