LoginSignup
1
0

Firebaseのパスワード再設定でちょっとハマった

Posted at

発生している問題・エラー

sendPasswordResetEmailのエラーをtry-catchでcatchできない。

パスワード再設定メールを送信する処理で、「そもそも登録されていないユーザーの場合」、
try-catchで「登録されていません」と表示したかった。

結論

存在する/しないが分かってしまうとブルートフォース攻撃の対象になりかねないのでエラー返すのをやめたとのこと
Googleさんより参照)
https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection?hl=ja#enable

※Firebase→Authenticatin→設定→ユーザーアクション で、メールの列挙型を無効にすればエラー返してくれる?(試していないです)

errorMessageは''空のまま。

            ElevatedButton(
              onPressed: () async {
                // エラーメッセージ
                String errorMessage = '';
                try {
                  await FirebaseAuth.instance
                      .sendPasswordResetEmail(email: _email.text);
                } on FirebaseAuthException catch (e) {
                // ⭐️ここに入らない
                  errorMessage = "エラーが発生しました。";
                  if (e.code == 'invalid-email') {
                    errorMessage = "無効なメールアドレスです。";
                  } else if (e.code == 'user-not-found') {
                    errorMessage = "メールアドレスに紐づくユーザーが見つかりませんでした。";
                  } else {
                    errorMessage = "予期しないエラーが発生しました。";
                  }
                } finally {
                  print(errorMessage);
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                     content: Text(errorMessage),
                 ));
                }
              },
              child: Text("送信"),
            ),```
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0