question

Kim Strasser avatar image
Kim Strasser asked

How can I avoid new accounts when I use LoginWithDeviceID?

I only want to use LoginWithIOSDeviceID and LoginWithAndroidDeviceID to log in the player to an existing recoverable account. I don't want to create a new anonymous account when I use LoginWithIOSDeviceID/LoginWithAndroidDeviceID.

If LoginWithDeviceID won't work because the player's device is not linked to a recoverable account, then I want to display text boxes so that the player can enter his username and password and I would use LoginWithPlayFab + LinkIOSDeviceID/LinkAndroidDeviceID to log in the player to his existing account. If the player has no account, then he needs to create a new recoverable account.

How can I use LoginWithDeviceID and LoginWithPlayFab together so that they don't always create a new anonymous account if it is not possible to log in to a recoverable account?

Where can I call LoginPlayFabAccount() in RegisterGuestPlayFabAccount() if I can not automatically log in with LoginWithDeviceID to a recoverable account?

private void RegisterGuestPlayFabAccount()
{
    PlayerDeviceId = ReturnMobileID();
    var requestIOS = new LoginWithIOSDeviceIDRequest { DeviceId = PlayerDeviceId, CreateAccount = false };
    var loginTask = PlayFabClientAPI.LoginWithIOSDeviceIDAsync(requestIOS);
    loginTask.ContinueWith(OnPlayFabRegisterGuestAccountComplete);
}

private void OnPlayFabRegisterGuestAccountComplete(Task<PlayFabResult<LoginResult>> task)
{
    if (task.Result.Result != null)
    {

    }
}

private void LoginPlayFabAccount()
{
    PlayerDeviceId = ReturnMobileID();
    var request = new LoginWithPlayFabRequest { TitleId = "BFD0A", Username = KeyboardTextUsername, Password = KeyboardTextPassword };
    var loginTask = PlayFabClientAPI.LoginWithPlayFabAsync(request);
    loginTask.ContinueWith(OnPlayFabLoginAccountComplete);
}

private void OnPlayFabLoginAccountComplete(Task<PlayFabResult<LoginResult>> task)
{        
    if (task.Result.Result != null)
    {

    }
}
Account Management
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Firstly, please keep CreateAccount false, if it is false PlayFab won’t create a new account when the deviceId hasn’t be registered. Clients will be unable to log in successfully when the deviceId is new. PlayFab will return AccountNotFound error to clients after receiving a LoginWithIOSDeviceID request. So, you can call the register and login function when the error name is AccountNotFound. You can refer to the following code and commends.

...
 private void OnPlayFabRegisterGuestAccountComplete(Task<PlayFabResult<LoginResult>> task)
    {
        if (task.Result.Error.Error == PlayFabErrorCode.AccountNotFound)
        {
            /*1. Let players choose if they already have an account. If no jump to 2, if yes jump to 3.
            2. Jump to the register UI Panel, let players enter the name, email, password, then call RegisterPlayFabUser. 
            3. Jump to the Login UI Panel, you can use LoginPlayFabAccount() function here.
            4. After register and login successfully, call LinkIOSDeviceID with stored DeviceID.*/
        }
       
        if (task.Result.Result != null)
        {
            
        }
    }
...
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.