2024-09-20 11:16:19 +01:00
|
|
|
import { env } from '$env/dynamic/private';
|
2024-04-20 04:39:16 +01:00
|
|
|
import { config } from '$lib/config';
|
2025-05-03 14:46:01 +01:00
|
|
|
import { createClient, type SupabaseClient } from '@supabase/supabase-js';
|
2024-03-22 06:30:24 +01:00
|
|
|
|
|
|
|
|
export let supabase: SupabaseClient;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should only be called on server files
|
|
|
|
|
*
|
|
|
|
|
* @returns supabase
|
|
|
|
|
*/
|
|
|
|
|
export const getServerSupabase = () => {
|
|
|
|
|
if (supabase) return supabase;
|
|
|
|
|
|
2024-09-22 16:28:54 +01:00
|
|
|
supabase = createClient(
|
|
|
|
|
config.supabaseConfig.url,
|
|
|
|
|
env.PRIVATE_SUPABASE_SERVICE_ROLE || 'some-key-here',
|
|
|
|
|
{
|
|
|
|
|
auth: {
|
|
|
|
|
persistSession: false,
|
|
|
|
|
autoRefreshToken: false,
|
|
|
|
|
detectSessionInUrl: false
|
|
|
|
|
}
|
2024-03-22 06:30:24 +01:00
|
|
|
}
|
2024-09-22 16:28:54 +01:00
|
|
|
);
|
2024-03-22 06:30:24 +01:00
|
|
|
|
|
|
|
|
return supabase;
|
|
|
|
|
};
|