Skip to content

Unity + Firebase Auth (Android build) #156

@giamendola

Description

@giamendola

Hello,

I'm trying to build my game for Android, i'm using the Firebase Auth (Email/Password), when i test in Unity Editor it works perfectly. But when i build to Android or Windows it gives the same error.

When i press the Login button, without put the e-mail:
image

And when i put the email, only gives me this:
image

Any suggestions?

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Firebase;
using Firebase.Auth;
using Firebase.Unity.Editor;
using UnityEngine.SceneManagement;

public class LoginScreen : MonoBehaviour {

GameObject inputEmail;
GameObject inputPassword;

string email, password;
Firebase.Auth.FirebaseAuth auth;
Firebase.Auth.FirebaseUser user;


void Start () {
    Debug.Log("Login");
    inputEmail = GameObject.Find("inputEmailText");
    inputPassword = GameObject.Find("inputPasswordText");
    InitializeFirebase();

}

void InitializeFirebase()
{
    auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
    auth.StateChanged += AuthStateChanged;
    AuthStateChanged(this, null);
}

void OnDestroy()
{
    auth.StateChanged -= AuthStateChanged;
}

void AuthStateChanged(object sender, System.EventArgs eventArgs)
{
    if (auth.CurrentUser != user)
    {
        bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null;
        if (!signedIn && user != null)
        {
            Debug.Log("Signed out " + user.UserId);
        }
        user = auth.CurrentUser;
        if (signedIn)
        {
            Debug.Log("Signed in " + user.UserId);
        }
    }
}


public void Authenticate()
{
    email = inputEmail.GetComponent<Text>().text;
    password = inputPassword.GetComponent<Text>().text;
    Debug.Log(email);
    Debug.Log(password);

    auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                newUser.DisplayName, newUser.UserId);
            SceneManager.LoadScene("Menu");
        });
}

public void CreateAuthentication()
{
    email = inputEmail.GetComponent<Text>().text;
    password = inputPassword.GetComponent<Text>().text;

    auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
        if (task.IsCanceled)
        {
            Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
            return;
        }
        if (task.IsFaulted)
        {
            Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
            return;
        }

        // Firebase user has been created.
        Firebase.Auth.FirebaseUser newUser = task.Result;
        Debug.LogFormat("Firebase user created successfully: {0} ({1})",
            newUser.DisplayName, newUser.UserId);

    });
}

}

(Using the Reporter from asset store)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions