【问题标题】:How to use sendEmailVerification() method如何使用 sendEmailVerification() 方法
【发布时间】:2019-08-17 16:16:13
【问题描述】:

尝试为 Firebase 设置 firebase_auth 包 Flutter 中的电子邮件/密码验证方法,但需要电子邮件验证方面的帮助。

我遇到了 firebase_auth 包提供的 sendEmailVerification(); 方法,但需要一些关于设置它的建议。请问有人有工作代码示例吗?

// 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});
}

任何有关正确设置和工作示例代码的帮助、建议、指导(如果可能)将不胜感激。

【问题讨论】:

    标签: firebase dart flutter firebase-authentication


    【解决方案1】:

    如果您创建FirebaseUser,此方法将起作用。可以这样使用:

    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();
    

    【讨论】:

    • 谢谢!没有意识到应该制作FirebaseUser
    • @Effie 不客气!考虑接受此答案,以便其他有此问题的人知道如何解决!
    • @R.Duggan 是否使用 sendEmailVerification() 自动登录用户?
    • @WilliamHumphries 我相信您需要获取他们登录时使用的密码和电子邮件,并从他们那里获得AuthCredential 以获取访问令牌,以便您确认是他们。欲了解更多信息,请查看pub.dev/packages/firebase_auth 的 flutter firebase_auth 包的文档
    猜你喜欢
    • 2018-05-14
    • 2019-03-13
    • 2021-01-25
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2018-09-15
    • 2017-12-17
    • 2021-05-15
    相关资源
    最近更新 更多