Reputation: 11
I an have an app where a user logs in with phone number and recieves an ATP. If data is available, then user is redirected to the welcome screen. If user data is not available, they are redirected to the profile setting screen - where they add their profile image name, address, phone number, email and a submit button. On pressing that data will be sent to the firebase.
I want is to verify the user's email before sending data to the firebase. How can i do that?
Attaching the code below of profile setting screen where i need to verify the email first.
Error i am getting:
Exception: Failed to update email: [firebase_auth/operation-not-allowed] This operation is not allowed. This may be because the given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section. [ Please verify the new email before changing email.
Widget orangeButton(String title, Function onPressed) {
return InkWell(
onTap: () => onPressed(),
child: Container(
width: Get.width,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [Colors.red, Colors.orange],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
alignment: Alignment.center,
child: Text(
title,
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
);
}
// This assumes you have a button set up to call this function
void handleSubmit() async {
if (formKey.currentState!.validate()) { // Ensure the form is valid
final authController = Get.find<AuthController>();
try {
await authController.updateEmail(emailController.text);
Get.snackbar(
'Email Updated',
'Please verify your new email address. A verification email has been sent to ${emailController.text}.',
backgroundColor: Colors.green,
snackPosition: SnackPosition.BOTTOM,
);
// You might want to navigate the user or disable the form until the email is verified
} catch (e) {
print(e);
Get.snackbar(
'Error',
e.toString(),
backgroundColor: Colors.red,
snackPosition: SnackPosition.BOTTOM,
);
}
}
}
void saveUserProfileData() {
// Your code to save other user profile details to Firestore or other databases
authController.storeUserInfo(
selectedImage,
nameController.text,
homeController.text,
phoneNumberController.text,
emailController.text,
url: authController.myUser.value.image ?? "",
homeLatLng: homeAddress,
);
}
Obx(() => authController.isProfileUploading.value
? Center(child: CircularProgressIndicator())
: orangeButton('Submit', handleSubmit),
I tried updating the email and setting it, but not finding a solution.
Upvotes: 0
Views: 15