[英]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
至于现在,我只能在下面捕获这些错误代码
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:对于不喜欢点击链接的任何人:
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.