mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-03 19:42:57 +00:00
65 lines
1.9 KiB
Dart
65 lines
1.9 KiB
Dart
import 'package:supabase_flutter/supabase_flutter.dart' as supabase;
|
|
|
|
void initializeSupabaseClient() {
|
|
// Additional client setup if needed
|
|
// For now, we use the default Supabase.instance.client
|
|
}
|
|
|
|
supabase.SupabaseClient? get supabaseClient {
|
|
try {
|
|
return supabase.Supabase.instance.client;
|
|
} catch (e) {
|
|
// Supabase not initialized
|
|
return null;
|
|
}
|
|
}
|
|
|
|
bool get isSupabaseInitialized => supabaseClient != null;
|
|
|
|
supabase.User? get currentSupabaseUser {
|
|
final client = supabaseClient;
|
|
return client?.auth.currentUser;
|
|
}
|
|
|
|
String? get currentSupabaseUserId => currentSupabaseUser?.id;
|
|
|
|
String? get currentSupabaseUserEmail => currentSupabaseUser?.email;
|
|
|
|
// Service role client for admin operations (like creating user profiles)
|
|
// This should be used server-side or with proper security measures
|
|
supabase.SupabaseClient? _serviceRoleClient;
|
|
|
|
supabase.SupabaseClient getServiceRoleClient() {
|
|
if (_serviceRoleClient != null) return _serviceRoleClient!;
|
|
|
|
// Note: In a production app, the service role key should be stored securely
|
|
// This is typically handled server-side via Edge Functions or similar
|
|
// For now, we'll fall back to the regular client if service role is not available
|
|
try {
|
|
const serviceRoleKey = String.fromEnvironment('SUPABASE_SERVICE_ROLE_KEY');
|
|
const url = String.fromEnvironment('SUPABASE_URL');
|
|
|
|
if (serviceRoleKey.isNotEmpty && url.isNotEmpty) {
|
|
_serviceRoleClient = supabase.SupabaseClient(url, serviceRoleKey);
|
|
return _serviceRoleClient!;
|
|
}
|
|
} catch (e) {
|
|
// Service role key not available, will use regular client
|
|
}
|
|
|
|
final client = supabaseClient;
|
|
if (client != null) {
|
|
return client;
|
|
}
|
|
|
|
// If no client is available, throw an exception
|
|
throw Exception('Supabase client not initialized');
|
|
}
|
|
|
|
Future<void> signOutCurrentSupabaseUser() async {
|
|
final client = supabaseClient;
|
|
if (client == null) return;
|
|
|
|
await client.auth.signOut();
|
|
}
|