-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabaseClient.ts
More file actions
25 lines (19 loc) · 802 Bytes
/
Copy pathsupabaseClient.ts
File metadata and controls
25 lines (19 loc) · 802 Bytes
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
import { createClient, SupabaseClient } from '@supabase/supabase-js';
let client: SupabaseClient | null = null;
export function getSupabaseClient(): SupabaseClient | null {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseAnonKey) {
console.warn('Supabase client not configured. Set NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY.');
return null;
}
if (supabaseUrl.includes('/rest/v1')) {
console.warn('NEXT_PUBLIC_SUPABASE_URL should be the base project URL (https://<ref>.supabase.co) without /rest/v1.');
}
if (!client) {
client = createClient(supabaseUrl, supabaseAnonKey, {
auth: { persistSession: false },
});
}
return client;
}