signInByFacebook method
Implementation
Future<Response> signInByFacebook(UserEntity entity) async {
emit(state.copy(isLoading: true));
final response = await handler.signInWithFacebook();
final result = response.data;
if (result != null && result.credential != null) {
final finalResponse = await handler.signUpWithCredential(
credential: result.credential!,
);
if (finalResponse.isSuccessful) {
final currentData = finalResponse.data?.user;
final user = entity.copy(
id: currentData?.uid ?? result.id,
email: result.email,
name: result.name,
photo: result.photo,
provider: AuthProvider.facebook.name,
);
final userResponse = await userHandler.create(user);
if (userResponse.isSuccessful || userResponse.snapshot != null) {
emit(state.copy(
isLoggedIn: true,
user: user,
firebaseUser: currentData,
));
} else {
emit(state.copy(error: userResponse.message));
}
return userResponse.copy(data: user);
} else {
emit(state.copy(error: finalResponse.message));
return finalResponse;
}
} else {
emit(state.copy(error: response.message));
return response;
}
}