How to handle Firebase auth errors on Unity

firebase authentication unity
unity firebase google sign in
firebase phone authentication unity
firebase unity
firebase unity api
firebase authentication tutorial
why use firebase authentication
firebase auth 2fa

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...

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;
}

Handle Errors with Cloud Storage for Unity, When in doubt, check the error returned, and see what the error message says. Note: By default, Cloud Storage buckets require Firebase Authentication to  Handle Errors with Cloud Storage for Unity. Contents. Handle Error Messages. Sometimes when you're building an app, things don't go as planned and an error occurs. When in doubt, check the error returned, and see what the error message says.

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).

Get Started with Firebase Authentication in Unity, Add the Firebase Unity SDK (specifically, FirebaseAuth.unitypackage ) to LogError Duration: 11:17 Posted: Mar 9, 2017 Handle Firebase iOS Auth Errors If the completion callback on Authentication methods receives an NSError argument that is not nil, an error has occurred. To dispatch to appropriate error-handling

FirebaseAuth.DefaultInstance.CreateUserWithEmailAndPasswordAsync (Email.text, Password.text).
ContinueWith (task => {
        if (task.IsCanceled) 
        {
            Debug.LogError ("CreateUserWithEmailAndPasswordAsync was canceled");
            return;
        }
        if (task.IsFaulted) 
        {
            Debug.LogError ("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
            //      
            ErrorText.text = "Error: " + task.Exception.InnerExceptions[0].Message;
            //
            return;
        }
});

I think this might be what you want.This will display "Error: " followed by what the message is and is really clean.

Example needed for handling auth exceptions · Issue #96 · firebase , handle specific errors for authorization requests (such as email being https://​github.com/firebase/quickstart-unity/blob/master/auth/testapp/  Contents. Handle Error Messages. Sometimes things don't go as planned and an error occurs. When in doubt, check the error returned and see what the error message says. The following code shows a custom error handler implementation that inspects the error code and error message returned by Firebase Storage.

Firebase Auth error in unity 2018.2.17f1 · Issue #269 · firebase , GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Sign up. Firebase.Auth.FirebaseUser user = auth.CurrentUser; // Get auth credentials from the user for re-authentication. The example below shows // email and password credentials but there are multiple possible providers, // such as GoogleAuthProvider or FacebookAuthProvider.

Unity Firebase Auth Freeze Catch Exception, Does anyone know how catch a Firebase Auth Exception? to login and every now and then I get an ANR error when trying to authenticate. I'm trying to build a login page with firebase auth plugin. But I don't know how to handle auth errors in a cross-platform way. For example, this are some PlatformException that I get when the user type the wrong password/email or there

firebase: How to handle Firebase auth errors on Unity, 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  Register your Unity project and configure it to use Firebase. If your Unity project already uses Firebase, then it's already registered and configured for Firebase. If you don't have a Unity project, you can download a sample app. Add the Firebase Unity SDK (specifically, FirebaseAuth.unitypackage) to your Unity project.

Comments
  • It seems like you are referring to legacy docs. Firebase is now part of google & new docs are available at firebase.google.com/docs/auth
  • I did followed the new doc but I don't find anything related to error handling in Unity: firebase.google.com/docs/auth/unity/password-auth There is something equivalent for ios but not for unity (ios: firebase.google.com/docs/auth/ios/errors ) Did I missed something?
  • That is correct, only thing that is exposed is task.Exception and it contains list of exceptions causing the issue but its really messy. Firebase did some changes in 4.0.3 sdk related to tasks dll file. I haven't checked it but u might wanna have a look.
  • So there is no way to get the FirebaseException original error except from the messy message from task.Exception, ok :/ Thanks for your feedback.
  • Why do't you raise support request to firebase or to thr github page. They are very responsive at both places & get us the answer here too.
  • Ah! Perfect this is the list I was looking for
  • Thanks for your answer, but the idea is to show a different log from the default Firebase one, in order for example to handle several langages. That's why I would have prefer a list of ID for each type of error instead of analysing the message string to detect the type of error and then display my own version to the user.
  • But maybe my question is rather a feature request and not a "bug"