-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase.ts
More file actions
45 lines (38 loc) · 1.23 KB
/
supabase.ts
File metadata and controls
45 lines (38 loc) · 1.23 KB
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
39
40
41
42
43
44
45
import { createClient } from '@supabase/supabase-js';
// Initialize Supabase client for server-side use
const supabaseUrl = process.env.VITE_SUPABASE_URL || '';
const supabaseAnonKey = process.env.VITE_SUPABASE_ANON_KEY || '';
let supabase: ReturnType<typeof createClient> | null = null;
try {
if (supabaseUrl && supabaseAnonKey) {
supabase = createClient(supabaseUrl, supabaseAnonKey);
} else {
console.warn('Missing Supabase credentials in environment variables');
}
} catch (error) {
console.error('Failed to initialize Supabase client:', error);
}
// Function to fetch professional profile data
export async function fetchProfessionalProfile(userId: number) {
if (!supabase) {
console.warn('Supabase client not initialized, skipping profile fetch');
return null;
}
try {
const { data, error } = await supabase
.from('professional_profiles')
.select('*')
.eq('user_id', userId)
.single();
if (error) {
console.warn('Error fetching professional profile:', error);
return null;
}
return data;
} catch (error) {
console.warn('Exception while fetching professional profile:', error);
return null;
}
}
// Export supabase instance
export { supabase };