I'm having the problem of sending the email verification link to a user while they are trying to register an account that was already created. I am coding with Flutter with Firebase as the back-end database.
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
abstract class BaseAuth {
Stream<String> get onAuthStateChanged;
Future<String> currentUser();
Future<String> resendVerifyEmail(BaseAuth auth, String email);
}
class Auth implements BaseAuth {...}
Future<String> currentUser() async {
final FirebaseUser user = await _firebaseAuth.currentUser();
print("Getting current user: " + user?.uid);
return user?.uid;
}
Future<String> resendVerifyEmail(BaseAuth auth, String email) async {
try {
final FirebaseUser user = await _firebaseAuth.currentUser();
user.sendEmailVerification();
return user?.uid;
} catch (e) {
print("An Error occurred while sending verification link");
print(e.toString());
return null;
}
}
Inside the try block, when calling the method currentUser(), the code exits and returns to the method that calls resendVerifyEmail without finishing the try-catch block.
I am having difficulty getting the email verification to resend inside of the popup that call resendVerifyEmail.
Please let me know any alternative ways to send email verification from Firebase with Flutter or what to do with this.
void _showVerifyEmailDialog(BuildContext context, String email) {
final BaseAuth auth = AuthProvider.of(context).auth;
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: new Text("Account Already Exists"),
content: new Text("Please verify account in the link sent to email"),
actions: <Widget>[
new FlatButton(
child: new Text("Resend verification email"),
onPressed: () {
Navigator.of(context).pop();
auth.resendVerifyEmail(); <- Called from this line in login.dart
Why is the code exiting at the statement below without moving to next line of sending email?
final FirebaseUser user = await _firebaseAuth.currentUser();