Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sendEmailVerification() method

Trying to setup the firebase_auth package for Firebase Email/Password Authentication method in Flutter, but need help with email verification.

I came accross the sendEmailVerification(); method provided by firebase_auth package, but need some advice on setting it up. Does anyone have a working code example to follow please?

// From firebase_auth package docs > https://pub.dartlang.org/documentation/firebase_auth/latest/firebase_auth/FirebaseUser/sendEmailVerification.html

Future<void> sendEmailVerification() async {
  // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
  // https://github.com/flutter/flutter/issues/26431
  // ignore: strong_mode_implicit_dynamic_method
  await FirebaseAuth.channel.invokeMethod(
      'sendEmailVerification', <String, String>{'app': _app.name});
}

Any help, advice, guidance with setting it up properly and working sample code to follow if possible would be much appreciated.

like image 235
Effie Avatar asked Mar 27 '19 06:03

Effie


1 Answers

This method will work if you make a FirebaseUser. It can be used like this:

await _auth.createUserWithEmailAndPassword (
  email: //wherever you set their email,
  password: //wherever you set their password,
).then((FirebaseUser user) {
  //If a user is successfully created with an appropriate email
if (user != null){
  user.sendEmailVerification();
}
})
.catchError();
like image 133
R. Duggan Avatar answered Nov 15 '22 11:11

R. Duggan