forked from deco-cx/deco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supabase.ts
38 lines (30 loc) · 1.42 KB
/
supabase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { supabase } from "./deps.ts";
let client: supabase.SupabaseClient | null = null;
const SUPABASE_LIVE_ENDPOINT_ENV_VAR = "SUPABASE_LIVE_ENDPOINT";
const SUPABASE_LIVE_ANON_KEY_ENV_VAR = "SUPABASE_LIVE_ANON_KEY";
const DEFAULT_SUPABASE_LIVE_ENDPOINT =
"https://ozksgdmyrqcxcwhnbepg.supabase.co";
// From supabase docs:
// "This key is safe to use in a browser if you have enabled Row Level Security for your tables and configured policies."
export const SUPABASE_LIVE_ENDPOINT = typeof Deno !== "undefined"
? Deno.env.get(SUPABASE_LIVE_ENDPOINT_ENV_VAR) ??
DEFAULT_SUPABASE_LIVE_ENDPOINT
: DEFAULT_SUPABASE_LIVE_ENDPOINT;
const DEFAULT_SUPABASE_LIVE_ANON_KEY =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im96a3NnZG15cnFjeGN3aG5iZXBnIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTY3MjM3NDYsImV4cCI6MTk3MjI5OTc0Nn0.HMdsG6NZlq6dvYFCK1_tuJh38TmsqLeN8H4OktTHt_M";
export const SUPABASE_LIVE_ANON_KEY = typeof Deno !== "undefined"
? Deno.env.get(SUPABASE_LIVE_ANON_KEY_ENV_VAR) ??
DEFAULT_SUPABASE_LIVE_ANON_KEY
: DEFAULT_SUPABASE_LIVE_ANON_KEY;
let userEndpoint = SUPABASE_LIVE_ENDPOINT;
let userKey = SUPABASE_LIVE_ANON_KEY;
export function setupSupabase(endpoint: string, key: string) {
userEndpoint = endpoint;
userKey = key;
}
export default function getSupabaseClient(accessToken?: string) {
if (!client) {
client = supabase.createClient(userEndpoint, accessToken || userKey);
}
return client;
}