简体   繁体   English

Flutter Firebase 授权密码重置

[英]Flutter Firebase Auth Password Reset

I'm trying to utilize the Firebase Auth sendPasswordResetEmail() call in my app.我正在尝试在我的应用程序中使用 Firebase Auth sendPasswordResetEmail() 调用。

In my auth file I declare the following:在我的授权文件中,我声明如下:

 Future<void> sendPasswordResetEmail(String email) async {
    return _firebaseAuth.sendPasswordResetEmail(email: email);
  }

I pass the Auth to my a form widget that takes in this password and has the following onPressed function once I submit.我将 Auth 传递给我的表单小部件,该小部件接受此密码并在我提交后具有以下 onPressed function。

onPressed: () async {
    var response = await checkEmail();
    setState(() {
        this._emailValidator = response;
    });
    if (_formKey.currentState.validate()) {
        _formKey.currentState.save();
        try {
            await widget.auth
                .sendPasswordResetEmail(_email);
        } catch (e) {
            print(e);
        }
    }

},

I get the following console message after running it with a proper email:使用正确的 email 运行它后,我收到以下控制台消息:

"Tried calling: sendPasswordResetEmail("test@email.com")" Note: I used a real email for this. “尝试调用:sendPasswordResetEmail("test@email.com")” 注意:我为此使用了真实的 email。

I've set up the Firebase email template system but have not received any email. Does anyone know how I can further troubleshoot this or why my email is not working?我已经设置了 Firebase email 模板系统,但还没有收到任何 email。有谁知道我该如何进一步解决这个问题或者为什么我的 email 不工作?

Thanks!谢谢!

I figured this out.我想通了。 I was not correctly passing the auth down from my auth file to the new file.我没有正确地将身份验证从我的身份验证文件传递到新文件。 As such, the method was being called on null, resulting in NoSuchMethodError.因此,该方法在 null 上被调用,导致 NoSuchMethodError。

pass your email to sendPasswordResetEmail将您的 email 传递给sendPasswordResetEmail

FirebaseAuth.instance.sendPasswordResetEmail(email: "test@.com").then((_) {
                      toast(
                          "link has been sent to your email for password reset");
                    }).catchError((error) {
                      showDialog(
                        context: context,
                        builder: (context) => ErrorLog(
                          text: error.message.toString(),
                        ),
                      );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM