feat: migrate prosappco from Firebase to NestJS REST API (Fase 2)
- Replace all Firebase* repositories with Api* repositories using HTTP + SharedPreferences JWT - Remove Firebase.initializeApp() and firebase_messaging background handler from main.dart - Update DI (app_di.dart) to inject Api* repositories instead of Firebase* ones - Replace all Timestamp/cloud_firestore usage with ISO 8601 String dates - Stub PhoneVerificationService (Firebase phone OTP → backend OTP when implemented) - Add ApiService singleton with JWT management in lib/services/ - Legacy firebase_*_repository.dart files preserved for Fase 4 cleanup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
726cf12fd2
commit
733384091c
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
@@ -86,18 +85,18 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
} else {
|
||||
switch (error) {
|
||||
case UpdatePassworErros.credentialsWrong:
|
||||
emit(const AuthStateFailure(message: "Contraseña incorrecta"));
|
||||
emit(const AuthStateFailure(message: "Contrasena incorrecta"));
|
||||
break;
|
||||
case UpdatePassworErros.userNotFound:
|
||||
emit(const AuthStateFailure(message: "Usuario no encontrado"));
|
||||
break;
|
||||
case UpdatePassworErros.unknown:
|
||||
emit(const AuthStateFailure(message: "Error inesperado. 🥸"));
|
||||
emit(const AuthStateFailure(message: "Error inesperado."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const AuthStateFailure(message: "Error inesperado. 🥸"));
|
||||
emit(const AuthStateFailure(message: "Error inesperado."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,81 +109,33 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
in phoneVerificationService.verifyPhoneNumber(event.phoneNumber)) {
|
||||
switch (event.type) {
|
||||
case PhoneAuthEventType.verificationCompleted:
|
||||
AuthCredential credential = event.data;
|
||||
print('Verificación completada. Credencial: $credential');
|
||||
final credential = event.data;
|
||||
print('Verificacion completada. Credencial: $credential');
|
||||
break;
|
||||
case PhoneAuthEventType.verificationFailed:
|
||||
FirebaseAuthException exception = event.data;
|
||||
print('Verificación fallida. Excepción: $exception');
|
||||
emit(AuthStateFailure(message: "Error inesperado. 🥸 $exception"));
|
||||
return; // Detener la ejecución aquí
|
||||
final exception = event.data;
|
||||
print('Verificacion fallida. Excepcion: $exception');
|
||||
emit(AuthStateFailure(message: "Error inesperado. $exception"));
|
||||
return;
|
||||
case PhoneAuthEventType.codeAutoRetrievalTimeout:
|
||||
String verificationId = event.data;
|
||||
print(
|
||||
'Tiempo de espera agotado para recuperar el código. ID: $verificationId');
|
||||
final verificationId = event.data as String;
|
||||
print('Tiempo de espera agotado. ID: $verificationId');
|
||||
emit(const AuthStateFailure(
|
||||
message: "Tiempo de espera agotado. 🥸",
|
||||
message: "Tiempo de espera agotado.",
|
||||
));
|
||||
break;
|
||||
case PhoneAuthEventType.codeSent:
|
||||
Map<String, dynamic> eventData = event.data;
|
||||
String verificationId = eventData['verificationId'];
|
||||
int? resendToken = eventData['resendToken'];
|
||||
print(
|
||||
'Código enviado. ID: $verificationId, resendToken: $resendToken');
|
||||
final eventData = event.data as Map<String, dynamic>;
|
||||
final verificationId = eventData['verificationId'] as String;
|
||||
final resendToken = eventData['resendToken'] as int?;
|
||||
print('Codigo enviado. ID: $verificationId, resendToken: $resendToken');
|
||||
_verificationId = verificationId;
|
||||
emit(const AuthStateVerifyOAuth(false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const AuthStateFailure(message: "Error inesperado. 🥸"));
|
||||
}
|
||||
}
|
||||
|
||||
void _linkWithPhoneNumber3(
|
||||
LinkWithPhoneNumber event, Emitter<AuthState> emit) async {
|
||||
emit(AuthStateProcess());
|
||||
|
||||
try {
|
||||
StreamSubscription<PhoneAuthEvent> subscription = phoneVerificationService
|
||||
.verifyPhoneNumber(event.phoneNumber)
|
||||
.listen((event) async {
|
||||
switch (event.type) {
|
||||
case PhoneAuthEventType.verificationCompleted:
|
||||
AuthCredential credential = event.data;
|
||||
print('Verificación completada. Credencial: $credential');
|
||||
break;
|
||||
case PhoneAuthEventType.verificationFailed:
|
||||
FirebaseAuthException exception = event.data;
|
||||
print('Verificación fallida. Excepción: $exception');
|
||||
break;
|
||||
case PhoneAuthEventType.codeAutoRetrievalTimeout:
|
||||
String verificationId = event.data;
|
||||
print(
|
||||
'Tiempo de espera agotado para recuperar el código. ID: $verificationId');
|
||||
break;
|
||||
case PhoneAuthEventType.codeSent:
|
||||
Map<String, dynamic> eventData = event.data;
|
||||
String verificationId = eventData['verificationId'];
|
||||
int? resendToken = eventData['resendToken'];
|
||||
print(
|
||||
'Código enviado. ID: $verificationId, resendToken: $resendToken');
|
||||
_verificationId = verificationId;
|
||||
emit(const AuthStateVerifyOAuth(false));
|
||||
break;
|
||||
}
|
||||
|
||||
if (event.type == PhoneAuthEventType.verificationFailed) {
|
||||
// Detener la suscripción si la verificación falla
|
||||
// subscription.cancel();
|
||||
emit(const AuthStateFailure(message: "Error inesperado. 🥸"));
|
||||
}
|
||||
});
|
||||
|
||||
// await _userRepository
|
||||
} catch (e) {
|
||||
emit(const AuthStateFailure(message: "Error inesperado. 🥸"));
|
||||
emit(const AuthStateFailure(message: "Error inesperado."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +144,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(AuthStateProcess());
|
||||
try {
|
||||
final bool isVerified = await _userRepository.linkWithOTP(
|
||||
event.phoneNumber, _verificationId!, event.code);
|
||||
event.phoneNumber, _verificationId ?? '', event.code);
|
||||
|
||||
if (isVerified) {
|
||||
emit(AuthStateSuccess());
|
||||
@@ -201,34 +152,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(const AuthStateVerifyOAuth(true));
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is FirebaseAuthException) {
|
||||
switch (e.code) {
|
||||
case "invalid-verification-code":
|
||||
emit(const AuthStateFailure(
|
||||
message: "Código de verificación incorrecto. 🥸",
|
||||
));
|
||||
break;
|
||||
|
||||
case "provider-already-linked":
|
||||
emit(const AuthStateFailure(
|
||||
message: "Cuenta ya vinculada. 🥸",
|
||||
));
|
||||
break;
|
||||
|
||||
case "credential-already-in-use":
|
||||
emit(const AuthStateFailure(
|
||||
message:
|
||||
"Este numero ya se encuentra registrado con otra cuenta. 🥸",
|
||||
));
|
||||
break;
|
||||
|
||||
default:
|
||||
emit(AuthStateFailure(message: "Error inesperado. 🥸 $e"));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
emit(AuthStateFailure(message: "Error inesperado. 🥸 $e"));
|
||||
}
|
||||
emit(AuthStateFailure(message: "Error inesperado. $e"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user