login with phone
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
@@ -33,6 +35,12 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
try {
|
||||
final bool isVerified = await _userRepository.verifyOTP(event.code);
|
||||
|
||||
if (isVerified) {
|
||||
emit(AuthStateSuccess());
|
||||
} else {
|
||||
emit(const AuthStateVerifyOAuth(true));
|
||||
}
|
||||
|
||||
(isVerified)
|
||||
? emit(AuthStateSuccess())
|
||||
: emit(const AuthStateVerifyOAuth(true));
|
||||
|
||||
@@ -26,15 +26,18 @@ class FirebaseUserRepository implements UserRepository {
|
||||
});
|
||||
}
|
||||
|
||||
// Stream<MyUser?> get user => _userStreamController.stream;
|
||||
|
||||
Future<void> updateFromFirebase(String userId) async {
|
||||
try {
|
||||
final myUser = await getMyUser(userId);
|
||||
_userStreamController.add(myUser);
|
||||
} catch (e) {
|
||||
log('Error en FirebaseUserRepository ${e.toString()}');
|
||||
_userStreamController.add(null);
|
||||
try {
|
||||
await createUser(userId);
|
||||
final myUser = await getMyUser(userId);
|
||||
_userStreamController.add(myUser);
|
||||
} catch (e) {
|
||||
_userStreamController.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +166,6 @@ class FirebaseUserRepository implements UserRepository {
|
||||
Future<MyUser> getMyUser(String myUserId) async {
|
||||
try {
|
||||
return usersCollection.doc(myUserId).get().then((value) {
|
||||
log('xd -- ${value.data().toString()}'); // Imprime el valor de value
|
||||
return MyUser.fromEntity(
|
||||
MyUserEntity.fromDocument(value.data()!),
|
||||
);
|
||||
@@ -203,4 +205,18 @@ class FirebaseUserRepository implements UserRepository {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> createUser(String userId) async {
|
||||
try {
|
||||
await usersCollection.doc(userId).set({
|
||||
'id': userId,
|
||||
'name': '',
|
||||
'email': '',
|
||||
'picture': '',
|
||||
});
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,6 @@ abstract class UserRepository {
|
||||
Future<void> updateUserInfo(String userId, Map<String, dynamic> data);
|
||||
|
||||
Future<String> uploadPicture(String file, String userId);
|
||||
|
||||
Future<void> createUser(String userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user