I created a simple password login in my Unity app following the doc and it works fine, however I would like to handle the different kind of errors and since task.Exception
doesn't return an error code I don't know how to proceed.
I found this but it doesn't seems to be the same Firebase version since the login method is different...
You can also get the currently signed-in user by calling CurrentUser . If a user isn't signed in, CurrentUser returns null. Note: CurrentUser might also return null because the auth object has not finished initializing.
By default, a session ends (times out) after 30 minutes of user inactivity. There is no limit to how long a session can last.
Registering Your Unity App with Firebase. In the console, select the Unity icon to get started with adding Firebase to your project. You can register both iOS and Android apps, but to do so, you'll have to provide an iOS bundle ID/Android package name. To find that information, open up your existing Unity project.
Firebase has a AuthError enum that tells you the meaning of each ErrorCode in the FirebaseException, the documentation is here: https://firebase.google.com/docs/reference/unity/namespace/firebase/auth
To get the error message in Spanish I am doing this:
public static string GetErrorMessage(Exception exception)
{
Debug.Log(exception.ToString());
Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException;
if (firebaseEx != null)
{
var errorCode = (AuthError)firebaseEx.ErrorCode;
return GetErrorMessage(errorCode);
}
return exception.ToString();
}
private static string GetErrorMessage(AuthError errorCode)
{
var message = "";
switch (errorCode)
{
case AuthError.AccountExistsWithDifferentCredentials:
message = "Ya existe la cuenta con credenciales diferentes";
break;
case AuthError.MissingPassword:
message = "Hace falta el Password";
break;
case AuthError.WeakPassword:
message = "El password es debil";
break;
case AuthError.WrongPassword:
message = "El password es Incorrecto";
break;
case AuthError.EmailAlreadyInUse:
message = "Ya existe la cuenta con ese correo electrónico";
break;
case AuthError.InvalidEmail:
message = "Correo electronico invalido";
break;
case AuthError.MissingEmail:
message = "Hace falta el correo electrónico";
break;
default:
message = "Ocurrió un error";
break;
}
return message;
}
I finally found a way to display only the error message using this:
FirebaseException error = task.Exception.InnerExceptions[0] as FirebaseException;
string errorMsg = error.ToString();
However it doesn't solve theoriginal problem, since it seems this is something missing in Firebase for Unity (at least for now).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With