signUpByEmail method
Implementation
Future<Response> signUpByEmail(UserEntity entity) async {
const cubitResponse = Response();
final email = entity.email;
final password = entity.password;
if (!Validator.isValidEmail(email)) {
emit(state.copy(error: "Email isn't valid!"));
return cubitResponse.copy(message: "Email isn't valid!");
} else if (!Validator.isValidPassword(password)) {
emit(state.copy(error: "Password isn't valid!"));
return cubitResponse.copy(message: "Password isn't valid!");
} else {
try {
emit(state.copy(isLoading: true));
final response = await handler.signUpWithEmailNPassword(
email: email,
password: password,
);
final result = response.data?.user;
if (result != null) {
final user = entity.copy(
id: result.uid,
email: result.email,
phone: result.phoneNumber,
name: result.displayName,
photo: result.photoURL,
);
final userResponse = await userHandler.create(user);
if (userResponse.isSuccessful || userResponse.snapshot != null) {
emit(state.copy(
isLoggedIn: true,
user: user,
firebaseUser: response.data?.user,
));
} else {
emit(state.copy(error: userResponse.message));
}
return userResponse.copy(data: user);
} else {
emit(state.copy(error: response.message));
return response;
}
} catch (e) {
emit(state.copy(error: e.toString()));
return cubitResponse.copy(message: e.toString());
}
}
}