checkUserExistence method
Implementation
Future<bool> checkUserExistence(String email, String phone) async {
try {
var payload = {"email": email, "phone": phone};
print("Checking user existence => Payload: $payload");
var response = await Requests.getDio().post('auth/check-email', data: payload);
print("Response => ${response.data}");
if (response.statusCode == 200) {
var data = response.data['data'];
bool emailExists = data['emailExist'] == true;
bool phoneExists = data['phoneExist'] == true;
emailExists = false;
if (emailExists || phoneExists) {
String message = "";
if (emailExists) {
message += "User with this email already exists. Please try logging in.";
}
if (phoneExists) {
if (message.isNotEmpty) message += "\n";
message += "User with this phone number already exists.";
}
CustomFlashWidget.showFlashMessage(
type: FlashType.error,
title: "User Exists",
duration: Duration(seconds: 10),
message: message,
);
return true;
}
}
} catch (e) {
print("Error checking user existence: $e");
return false;
}
return false;
}