Error code with non-English character.
API: firebase_auth: 0.18.0+1.
Example:
The error code "email-already-in-use" looks like this:
emaıl-already-ın-use
Steps to reproduce the behavior:
Use this sample code to register a user in Firebase
```
try {
UserCredential result = await _auth.createUserWithEmailAndPassword(
email: emailCont.text, password: passCont.text);
user = result.user;
if (user != null) {
setState(() {
userValid = true;
});
} else {
setState(() {
userValid = false;
});
}
} catch (e) {
if (e is FirebaseAuthException) {
if (e.code == 'email-already-in-use') {
return ToolUtil.getState().showsnack(
'User with Email Already exists', _scaffoldKeyRegister);
}
}
}
2. See error or incorrect behavior:
_[firebase_auth/ema**ı**l-already-**ı**n-use] The email address is already in use by another account._
### Expected behavior
Error code only in English characters.
---
---
### Flutter doctor
<details><summary>Click To Expand</summary>
[√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Version 10.0.14393], locale en-US)
• Flutter version 1.20.4 at C:\Users\ASUS\AppData\Local\Android\flutter
• Framework revision fba99f6cf9 (9 days ago), 2020-09-14 15:32:52 -0700
• Engine revision d1bc06f032
• Dart version 2.9.2
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at C:\Users\ASUS\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 47.1.1
• Dart plugin version 192.8052
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] Connected device (1 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
</details>
---
### Flutter dependencies
Run `flutter pub deps -- --style=compact` and paste the output below:
<details><summary>Click To Expand</summary>
Dart SDK 2.9.2
Flutter SDK 1.20.4
infopower 9.0.6+36
dependencies:
dev dependencies:
transitive dependencies:
```
Hi @altayhunoglu,
I am unable to replicate the issue.
I/flutter (25761): User with Email Already exists
I tried below code sample on latest stable (1.20.4)
code sample
void _register() async {
try {
UserCredential userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: "[email protected]",
password: "SuperSecretPassword!"
);
User user = userCredential.user;
if (user != null) {
setState(() {
userValid = true;
});
} else {
setState(() {
userValid = false;
});
}
}catch (e) {
if (e is FirebaseAuthException) {
if (e.code == 'email-already-in-use') {
print(
'User with Email Already exists');
}
}
}
}
}
Can you try the official plugin example and see if you still get the same behavior ?
Thanks
Hello @darshankawar,
First of all, may I ask if you know why it is not "ERROR_EMAIL_ALREADY_IN_USE" but "email-already-in-use" instead?
There must be some kind of conversion to lowercase and it causes the problem as my machine was once in Turkish.
In Turkish the lowercase of "I" is "ı"
So, indeed I can simply solve this individual problem like that:
if (e.code?.toUpperCase() =="EMAIL-ALREADY-IN-USE") {
return ToolUtil.getState().showsnack(
AppLocalizations.of(context).translate('email-already-in-use'),
_scaffoldKeyRegister);
}
Actually the correct question should be why there isn't an enum provided by firebase_auth that we can access to compare the error codes? Not very nice to compare with plain string specially when firebase changes those strings -.-
@leonardocustodio you'd still have the same problem though right? In order to generate an enum value you need to know the string value, which in this case seems to be a language problem so the enums wouldn't match up anyway.
@altayhunoglu Are you running anything "none standard" here? E.g. an emulator with a different language set etc? Would be interesting to replicate this.
@Ehesp yes, it wouldn't match if firebase changed the string values and the firebase auth package doesn't but as I said in the #3402 in my opinion at least, it's way easier to the package to keep uptodate with firebase string values than each developer alone. Also, when the package is responsible for that there is a lot of developers that can spot that the strings have changed and open an issue to report or make a pull request to fix it. But a developer alone, if he doesn't check often if the values haven't changed who knows how much time it will take for him to know the app isn't working as expected.
I know there is no perfect solution but from where I see this one looks the less painful one. But I could be wrong ;)
The native errors (e.g. permission denied) need to be converted to Dart-land code so this will always be required. That discussion is for the other PR anyway.
This is an issue which needs fixing regardless though - hopefully it can be replicated easily.
@leonardocustodio you'd still have the same problem though right? In order to generate an enum value you need to know the string value, which in this case seems to be a language problem so the enums wouldn't match up anyway.
@altayhunoglu Are you running anything "none standard" here? E.g. an emulator with a different language set etc? Would be interesting to replicate this.
@Ehesp hello,
You are right. I use emulator in Turkish. I will try after changing the language, as soon as possible.
Hey @altayhunoglu. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@altayhunoglu if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
we have the same problem..
today I updated the packages and using latest firebase packages..
normally I was getting an error code as "ERROR_INVALID_EMAIL"
but after the update, the error code is "ınvalıd-emaıl"
as you see it is small I (it is i without point). Because in turkish there is i and ı and also İ and I. (one is with point another not).
I could fix this problem by using toUpperCase method but it does not work. Because somehow, it behaves very turkic. That means
when I use upper method, small ı becomes I but it is not same "I" in english because english capital I is coming from "i"
that why when I do something like
"ınvalıd-emaıl".toUpperCase() == "INVALID_EMAIL"
it returns false. So this problem occurred after the update. language of my partner's computer is Turkish and mine is English. and I see the error as expected.
I/flutter (25906): firebase_auth/invalid-email] The email address is badly formatted.
I/flutter (25906): invalid-email
so somehow, the latest version of the package, uses windows's system language for the error codes..
Hope it helps for solving this problem.