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