I am just starting to check out Firebase. To start, I want to use it for Authentication and Database. I used their guide to set up my project, so I have a project in the backend, I have the SDK for Authentication imported, I have the plist file in my Unity project.
I’ve tried a few things, all within the Unity editor, and they don’t seem to be working, at least on the backend side. In Unity I am hitting all the right spots in my code, according to my debug messages. I am creating a Firebase user, but the user doesn’t appear in the Firebase backend. The code indicates that the user is created though. Here is the code I’m using:
FirebaseAuth _auth;
FirebaseUser _user;
void Start()
{
InitializeFirebase();
_auth.CreateUserWithEmailAndPasswordAsync("mattbrand@gmail.com", "testtest").ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}
Debug.Log("Complete");
// Firebase user has been created.
_user = task.Result;
Debug.LogFormat("Firebase user created successfully: " + _user.DisplayName + " " + _user.UserId);
});
}
void OnDestroy()
{
if (_auth != null)
{
_auth.StateChanged -= AuthStateChanged;
_auth = null;
}
}
void InitializeFirebase()
{
Debug.Log("InitializeFirebase");
_auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
_auth.StateChanged += AuthStateChanged;
AuthStateChanged(this, null);
}
void AuthStateChanged(object sender, System.EventArgs eventArgs)
{
Debug.Log("AuthStateChanged!");
if (_auth != null)
Debug.Log("_auth.CurrentUser = " + _auth.CurrentUser + " _user = " + _user);
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);
}
}
}
Anyone with experience with Firebase can help me on this?