I have created a login system using Playfab. But the problem is when I change my scene it automatically logs out. Now, is there any solution to this? I mean can I keep logged in every scene?
public Text messageText;
public Text messageReg;
public Text messagelog;
private string userEmail;
private string userPassword;
private string username;
public GameObject loginPanel;
public InputField emailInput;
public static PlayfabManager PFM;
public void OnEnable()
{
if (PlayfabManager.PFM == null)
{
PlayfabManager.PFM = this;
}
else
{
if (PlayfabManager.PFM != this)
{
Destroy(this.gameObject);
}
}
DontDestroyOnLoad(this.gameObject);
}
void Start()
{
if (string.IsNullOrEmpty(PlayFabSettings.TitleId))
{
PlayFabSettings.TitleId = " CFB1C";
}
//PlayerPrefs.DeleteAll();
if (PlayerPrefs.HasKey("EMAIL"))
{
userEmail = PlayerPrefs.GetString("EMAIL");
userPassword = PlayerPrefs.GetString("PASSWORD");
var request = new LoginWithEmailAddressRequest
{
Email = userEmail,
Password = userPassword
};
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
}
}
#region Login
private void OnLoginSuccess(LoginResult result)
{
Debug.Log("Logged In!");
PlayerPrefs.SetString("EMAIL", userEmail);
PlayerPrefs.SetString("PASSWORD", userPassword);
messagelog.text = "Logged In!";
}
private void OnRegisterSuccess(RegisterPlayFabUserResult result)
{
Debug.Log("Register and logged In!");
PlayerPrefs.SetString("EMAIL", userEmail);
PlayerPrefs.SetString("PASSWORD", userPassword);
messageReg.text = "Register and logged In!";
}
private void OnLoginFailure(PlayFabError error)
{
var registerRequest = new RegisterPlayFabUserRequest
{
Email = userEmail,
Password = userPassword,
Username = username,
};
PlayFabClientAPI.RegisterPlayFabUser(registerRequest, OnRegisterSuccess, OnRegisterFailure);
}
private void OnRegisterFailure(PlayFabError error)
{
Debug.LogError(error.GenerateErrorReport());
}
public void GetUserEmail(string emailIn)
{
userEmail = emailIn;
}
public void GetUserPassword(string passwordIn)
{
userPassword = passwordIn;
}
public void GetUsername(string usernameIn)
{
username = usernameIn;
}
public void OnClickLogin()
{
var request = new LoginWithEmailAddressRequest
{
Email = userEmail,
Password = userPassword
};
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnLoginFailure);
}