My register user is working perfectly, however when i try to log a user in i do not get any kind of message, successful login or failed login. I am trying to log my user in then move to my logged in screen. If anyone is able to see what it is i am doing wrong i would be very thankful! I will provided my code below. Thank you for your help!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Text.RegularExpressions;
using UnityEngine.SceneManagement;
using Firebase;
using Firebase.Auth;
public class Login : MonoBehaviour {
public GameObject email;
public GameObject password;
private string Email;
private string Password;
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
void Update () {
if (email.GetComponent<InputField>().isFocused){
password.GetComponent<InputField>().Select();
}
if (Password != ""&&Password != ""){
LoginButton();
}
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
}
public void LoginButton()
{
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("LoginScreen");
});
}
}
Replace ContinueWith with ContinueWithOnMainThread, I think you should be good. If not, make sure you've enabled email sign in in the Firebase console.
I suspect that everything's working as expected, but because you're using ContinueWith your SceneManager logic is happening off of the main thread. In the best case scenario, this just won't work. In the worst case, you might see a crash.
See my article on threading in Unity and my video on Authentication for more information.
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