Settings finalizadas

This commit is contained in:
2026-03-18 20:03:32 +00:00
parent 6322e8d798
commit 1794208143
7 changed files with 399 additions and 401 deletions

View File

@@ -2,27 +2,19 @@ import 'package:supabase_flutter/supabase_flutter.dart';
import '../constants/app_constants.dart';
class SupabaseService {
static final SupabaseClient _supabase = Supabase.instance.client;
static SupabaseClient get _supabase => Supabase.instance.client;
// Initialize Supabase
static Future<void> initialize() async {
try {
print('DEBUG: Inicializando Supabase...');
print('DEBUG: URL: ${AppConstants.supabaseUrl}');
print(
'DEBUG: AnonKey: ${AppConstants.supabaseAnonKey.substring(0, 10)}...',
);
await Supabase.initialize(
url: AppConstants.supabaseUrl,
anonKey: AppConstants.supabaseAnonKey,
);
print('DEBUG: Supabase inicializado com sucesso!');
// Test connection
final currentUser = _supabase.auth.currentUser;
print('DEBUG: Usuário atual: ${currentUser?.email ?? 'null'}');
} catch (e) {
print('DEBUG: Erro ao inicializar Supabase: $e');
rethrow;
@@ -39,26 +31,18 @@ class SupabaseService {
required String name,
}) async {
try {
print('DEBUG: Criando conta - Email: $email, Name: $name');
final response = await _supabase.auth.signUp(
email: email,
password: password,
data: {'name': name},
);
print('DEBUG: Conta criada! User ID: ${response.user?.id}');
// Check if user was created successfully
if (response.user != null) {
print('DEBUG: Usuário criado com sucesso!');
return response;
} else {
print('DEBUG: Falha ao criar usuário - response.user é null');
throw Exception('Falha ao criar usuário. Tente novamente.');
throw Exception('Falha ao criar usuário.');
}
} catch (e) {
print('DEBUG: Erro no signUp: $e');
throw Exception('Erro ao criar conta: $e');
}
}
@@ -69,17 +53,11 @@ class SupabaseService {
required String password,
}) async {
try {
print('DEBUG: Fazendo login - Email: $email');
final response = await _supabase.auth.signInWithPassword(
return await _supabase.auth.signInWithPassword(
email: email,
password: password,
);
print('DEBUG: Login realizado! User ID: ${response.user?.id}');
return response;
} catch (e) {
print('DEBUG: Erro no signIn: $e');
throw Exception('Erro ao fazer login: $e');
}
}
@@ -88,9 +66,7 @@ class SupabaseService {
static Future<void> signOut() async {
try {
await _supabase.auth.signOut();
print('DEBUG: Logout realizado');
} catch (e) {
print('DEBUG: Erro no signOut: $e');
throw Exception('Erro ao sair: $e');
}
}
@@ -99,27 +75,34 @@ class SupabaseService {
static Future<void> resetPassword(String email) async {
try {
await _supabase.auth.resetPasswordForEmail(email);
print('DEBUG: Email de reset enviado para: $email');
} catch (e) {
print('DEBUG: Erro no resetPassword: $e');
throw Exception('Erro ao redefinir senha: $e');
}
}
// Update user profile
static Future<void> updateProfile({String? name, String? email}) async {
try {
final updates = <String, dynamic>{};
if (name != null) updates['name'] = name;
final userAttributes = UserAttributes(
data: updates.isNotEmpty ? updates : null,
email: email,
);
await _supabase.auth.updateUser(userAttributes);
} catch (e) {
throw Exception('Erro ao atualizar perfil: $e');
}
}
// Test connection to Supabase
static Future<bool> testConnection() async {
try {
print('DEBUG: Testando conexão com Supabase...');
// Test with auth service instead of database
final session = _supabase.auth.currentSession;
print('DEBUG: Sessão atual: ${session != null ? 'ativa' : 'null'}');
// Try to get auth settings (this should work even without tables)
print('DEBUG: Conexão básica funcionando!');
return true;
} catch (e) {
print('DEBUG: Erro na conexão: $e');
return false;
}
}