简体   繁体   English

Flutter Firebase Auth Exception 的错误代码是什么?

[英]what are the error codes for Flutter Firebase Auth Exception?

I have tried to read this thread List of Authorisation errors with Firebase login , and also I have tried to search, but I just can find admin SDK authentication error in here here我试过阅读这个线程List of Authorization errors with Firebase login ,我也试过搜索,但我只能在这里找到 admin SDK authentication error

those error code from those links are different from the error code for Firebase Auth for Flutter app这些链接中的错误代码与 Firebase Auth for Flutter 应用程序的错误代码不同

I mean, I need the error codes in here我的意思是,我需要这里的错误代码

Future<void> signInUsingEmail({required String email, required String password}) async {
    try {
      await _auth.signInWithEmailAndPassword(email: email, password: password);
    } on FirebaseAuthException catch (error) {

      // I need the error.code in here

      print(error.code);
      

    }

could I know all available error codes?我能知道所有可用的错误代码吗? so I can write my own error message in my own language.所以我可以用我自己的语言写我自己的错误信息。 as for now, I can only catch these error codes below至于现在,我只能在下面捕获这些错误代码

  • "too-many-requests" “太多的请求”
  • "wrong-password" “密码错误”
  • "network-request-failed" “网络请求失败”

what else?还有什么?

For the signInWithEmailAndPassword method for Flutter, you will find the error codes in the firebase_auth package documentation .对于 Flutter 的signInWithEmailAndPassword方法,您将在firebase_auth package 文档中找到错误代码。

They are actually the same than the JS SDK ones: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#error-codes_12它们实际上与 JS SDK 相同: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#error-codes_12

So I created thisgist And it's basically a handler for some common firebase auth exceptions.所以我创建了这个要点它基本上是一些常见的 firebase 身份验证异常的处理程序。

This is an example on how to use it这是一个关于如何使用它的例子

Future createUser(String email, String password) async {
    try {
      UserCredential customUserCredential = await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
              email: email, password: password);
      return customUserCredential.user!.uid;
    } on FirebaseAuthException catch (authError) {
      throw CustomAuthException(authError.code, authError.message!);
    } catch (e) {
      throw CustomException(errorMessage: "Unknown Error");
    }

For anyone that doesn't like clicking on links:对于不喜欢点击链接的任何人:

signInWithEmailAndPassword 使用电子邮件和密码登录

  • wrong-passord : Thrown if the password is invalid for the given email, or the account corresponding to the email does not have a password set. wrong-passord :如果给定 email 的密码无效,或者 email 对应的帐户没有设置密码,则抛出此错误。
  • invalid-email : Thrown if the email address is not valid. invalid-email :如果 email 地址无效则抛出。
  • user-disabled : Thrown if the user corresponding to the given email has been disabled. user-disabled :如果与给定 email 对应的用户已被禁用,则抛出此错误。
  • user-not-found : Thrown if there is no user corresponding to the given email. user-not-found :如果没有与给定 email 对应的用户,则抛出此错误。

createUserWithEmailAndPassword createUserWithEmailAndPassword

  • email-already-in-use : Thrown if there already exists an account with the given email address. email-already-in-use :如果已经存在具有给定 email 地址的帐户,则抛出。
  • invalid-email : Thrown if the email address is not valid. invalid-email :如果 email 地址无效则抛出。
  • operation-not-allowed : Thrown if email/password accounts are not enabled. operation-not-allowed :如果未启用电子邮件/密码帐户,则抛出此错误。 Enable email/password accounts in the Firebase Console, under the Auth tab.在 Firebase 控制台的 Auth 选项卡下启用电子邮件/密码帐户。
  • weak-password : Thrown if the password is not strong enough. weak-password :如果密码不够强则抛出。

signInWithCredential 使用凭据登录

  • account-exists-with-different-credential : Thrown if there already exists an account with the email address asserted by the credential. account-exists-with-different-credential :如果已经存在一个帐户,该帐户的地址为 email,则该帐户的地址由凭证声明。 Resolve this by calling fetchSignInMethodsForEmail and then asking the user to sign in using one of the returned providers.通过调用 fetchSignInMethodsForEmail 然后要求用户使用返回的提供程序之一登录来解决此问题。 Once the user is signed in, the original credential can be linked to the user with linkWithCredential.用户登录后,可以使用 linkWithCredential 将原始凭据链接到用户。
  • invalid-credential : Thrown if the credential is malformed or has expired. invalid-credential :如果凭证格式错误或已过期,则抛出此错误。
  • operation-not-allowed : Thrown if the type of account corresponding to the credential is not enabled. operation-not-allowed :如果与凭证对应的帐户类型未启用,则抛出此错误。 Enable the account type in the Firebase Console, under the Auth tab.在 Firebase 控制台的 Auth 选项卡下启用帐户类型。
  • user-disabled : Thrown if the user corresponding to the given credential has been disabled. user-disabled :如果与给定凭据对应的用户已被禁用,则抛出该异常。
  • user-not-found : Thrown if signing in with a credential from EmailAuthProvider.credential and there is no user corresponding to the given email. user-not-found :如果使用来自 EmailAuthProvider.credential 的凭据登录并且没有与给定 email 对应的用户,则抛出此错误。
  • wrong-password : Thrown if signing in with a credential from EmailAuthProvider.credential and the password is invalid for the given email, or if the account corresponding to the email does not have a password set. wrong-password :如果使用来自 EmailAuthProvider.credential 的凭据登录并且密码对于给定的 email 无效,或者如果与 email 对应的帐户没有设置密码,则抛出此错误。
  • invalid-verification-code : Thrown if the credential is a PhoneAuthProvider.credential and the verification code of the credential is not valid. invalid-verification-code :如果凭证是 PhoneAuthProvider.credential 并且凭证的验证码无效,则抛出此错误。
  • invalid-verification-id : Thrown if the credential is a PhoneAuthProvider.credential and the verification ID of the credential is not valid.id. invalid-verification-id :如果凭证是 PhoneAuthProvider.credential 并且凭证的验证 ID 不是 valid.id,则抛出此错误。

reauthenticateWithCredential reauthenticateWithCredential

  • user-mismatch : Thrown if the credential given does not correspond to the user. user-mismatch :如果给定的凭证与用户不对应,则抛出。
  • user-not-found : Thrown if the credential given does not correspond to any existing user. user-not-found :如果给定的凭据不对应于任何现有用户,则抛出此错误。
  • invalid-credential : Thrown if the provider's credential is not valid. invalid-credential :如果提供者的凭据无效,则抛出此错误。 This can happen if it has already expired when calling link, or if it used invalid token(s).如果它在调用链接时已经过期,或者它使用了无效的令牌,则可能会发生这种情况。 See the Firebase documentation for your provider, and make sure you pass in the correct parameters to the credential method.请参阅您的提供商的 Firebase 文档,并确保将正确的参数传递给凭证方法。
  • invalid-email : Thrown if the email used in a EmailAuthProvider.credential is invalid. invalid-email :如果在 EmailAuthProvider.credential 中使用的 email 无效,则抛出此错误。
  • wrong-password : Thrown if the password used in a EmailAuthProvider.credential is not correct or when the user associated with the email does not have a password. wrong-password :如果在 EmailAuthProvider.credential 中使用的密码不正确或与 email 关联的用户没有密码,则抛出此错误。
  • invalid-verification-code : Thrown if the credential is a PhoneAuthProvider.credential and the verification code of the credential is not valid. invalid-verification-code :如果凭证是 PhoneAuthProvider.credential 并且凭证的验证码无效,则抛出此错误。
  • invalid-verification-id : Thrown if the credential is a PhoneAuthProvider.credential and the verification ID of the credential is not valid. invalid-verification-id :如果凭证是 PhoneAuthProvider.credential 并且凭证的验证 ID 无效,则抛出此错误。

signInWithAuthProvider 登录WithAuthProvider

  • user-disabled : Thrown if the user corresponding to the given email has been disabled. user-disabled :如果与给定 email 对应的用户已被禁用,则抛出此错误。

signInAnonymously 匿名登录

  • operation-not-allowed : Thrown if anonymous accounts are not enabled. operation-not-allowed :如果未启用匿名帐户,则抛出。 Enable anonymous accounts in the Firebase Console, under the Auth tab.在 Firebase 控制台的 Auth 选项卡下启用匿名帐户。

signInWithEmailLink 使用电子邮件链接登录

  • expired-action-code : Thrown if OTP in email link expires. expired-action-code :如果 email 链接中的 OTP 过期,则抛出。
  • invalid-email : Thrown if the email address is not valid. invalid-email :如果 email 地址无效则抛出。
  • user-disabled : Thrown if the user corresponding to the given email has been disabled. user-disabled :如果与给定 email 对应的用户已被禁用,则抛出此错误。
TextButton(
            onPressed: () async {
              try {
                //final user = FirebaseAuth.instance.currentUser;
                final email = _emailController.text;
                final password = _passwordController.text;
                // await FirebaseAuth.instance //   final userCredential =
                //     .signInWithEmailAndPassword(
                //         email: email, password: password);
                AuthService.firebase()
                    .logIn(email: email, password: password);
                final user = AuthService.firebase().currentUser;
                if (user?.isEmailVerified ?? false) {
                  Navigator.of(context).pushNamedAndRemoveUntil(
                      emailRoute, (route) => false);
                } else {
                  Navigator.of(context)
                      .pushNamedAndRemoveUntil(noteRoute, (route) => false);
                }

                //devtools.log(userCredential.toString());
                //This line of text may not work to print data
                // print(userCredential.toString());
              } on FirebaseAuthException catch (e) {
                if (e.code == 'network-request-failed') {
                  showErrorDialog(context, 'No Internet Connection');
                  //devtools.log('No Internet Connection');
                } else if (e.code == "wrong-password") {
                  return showErrorDialog(
                      context, 'Please Enter correct password');
                  //devtools.log('Please Enter correct password');
                  //print('Please Enter correct password');
                } else if (e.code == 'user-not-found') {
                  showErrorDialog(context, 'Email not found');
                  // print('Email not found');
                }  else if (e.code == 'too-many-requests') {
                  return showErrorDialog(
                      context, 'Too many attempts please try later');
                  //print('Too many attempts please try later');
                } else if (e.code == 'unknwon') {
                  showErrorDialog(
                      context, 'Email and password field are required');
                  //print('Email and password field are required');
                } else if (e.code == 'unknown') {
                  showErrorDialog(
                      context, 'Email and Password Fields are required');
                  //print(e.code);
                } else {
                  print(e.code);
                }
              }
            },
            child: const Text('Login')),

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

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