When I run CreateUserWithEmailAndPasswordAsync() the task returns as IsCompleted and the FirebaseUser is also not null, but the UserID and email are null/empty. I can see the new user (with UserID) in the firebase console.
The same thing happens when trying to SignInWithEmailAndPasswordAsync() with the newly created User. But when I SignInWithEmailAndPasswordAsync() with an older user account everything works fine.
It's strange because it is the same code I used a year ago. In the mean time I did update the Firebase SDK to 7.0.2. Could that be the cause of the issue?
Here is my code for creating a new user:
public static async Task<CallbackMessage> RegisterNewUser(string email, string password)
{
CallbackMessage callback = new CallbackMessage();
callback.isSuccess = false;
if (!await DatabaseManager.CheckConnection())
{
callback.notConnected = true;
return callback;
}
return await auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task =>
{
if (task.IsCanceled)
{
callback.errorMessage = "Create User was canceled";
}
else if (task.IsFaulted)
{
callback.errorMessage = GetErrorMessage(task.Exception);
}
else if (task.IsCompleted)
{
FirebaseUser newUser = task.Result;
Debug.Log("User created succesfully! userID: " + newUser.UserId);
callback.userID = newUser.UserId;
callback.email = newUser.Email;
callback.isSuccess = true;
}
CleanTask(task);
return callback;
});
}
Could really use a nudge in the right direction on this one :)
I was able to solve it. Apologies for doubting the Firebase Auth service.
In my AuthStateChanged code I added a Signout() whenever a user signed in, but wasn't emailVerified yet. That's where the problem was.
My guess what happened: When user creation is called it signs the user in immediately, then goes to Firebase to set things up there. In the mean time I sign out the user because it's not email verified. When the callback comes back it looks for the FirebaseUser that it signed in before going to Firebase, but finds nothing.
Something like pulling the chair from underneath someone as he's about to sit :P