【问题标题】:How to handle Firebase password reset email errors Flutter如何处理 Firebase 密码重置电子邮件错误 Flutter
【发布时间】:2021-04-10 19:26:19
【问题描述】:

我正在制作一个简单的密码重置对话框,它将通过 firebase 向用户发送密码重置电子邮件。一切正常,但是,我希望能够相应地捕获和处理错误。我似乎无法弄清楚如何去做。例如,当用户的互联网连接中断时,我希望他们看到一条消息,说明他们的密码重置电子邮件不是通过快餐店发送的。

我的代码:

// Send user an email for password reset
Future<void> _resetPassword(String email) async {
  await auth.sendPasswordResetEmail(email: email);
}

// This will handle the password reset dialog for login_password
void passwordResetDialog(context, email) {
  displayDialog(
    context,
    title: "Forgot Password?",
    content:
        "We will send you an email with a password reset link. Press on that link and follow the instructions from there.",
    leftOption: "No",
    onPressedLeftOption: () {
      // Close dialog
      Navigator.of(context).pop();
    },
    rightOption: "Yes",
    onPressedRightOption: () {
      
      // Send reset password email
      _resetPassword(email);

      // Close dialog
      Navigator.of(context).pop();

      displaySnackBar(
        context,
        contentText: "Password reset email sent",
        durationTime: 7,
      );
    },
  );
}

【问题讨论】:

    标签: firebase flutter dart firebase-authentication


    【解决方案1】:

    你可以这样做:

    try {
     await auth.sendPasswordResetEmail(email: email);
    } on FirebaseAuthException catch (e) {
     print(e.code);
     print(e.message);
    // show the snackbar here
    }
    

    阅读更多here

    【讨论】:

    • 谢谢你的回答,我已经实现了。但是,如果用户没有互联网连接,它似乎不会提供错误。有什么办法可以解决吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2018-02-23
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-10-15
    相关资源
    最近更新 更多