question

anudeep avatar image
anudeep asked

Having issues registering/Signing up new accounts

private void AddAccountAndPassword()
    {
        
        //Any time we attempt to register a player, first silently authenticate the player.
        //This will retain the players True Origination (Android, iOS, Desktop)
        SilentlyAuthenticate((result) =>
        {

            if (result == null)
            {
                //something went wrong with Silent Authentication, Check the debug console.
                OnPlayFabError.Invoke(new PlayFabError()
                {
                    Error = PlayFabErrorCode.UnknownError,
                    ErrorMessage = "Silent Authentication by Device failed"
                    

                }) ;
                Debug.Log("Result is null for silent authentication.");
                
            }
            Debug.Log(result);
            
            //Note: If silent auth is success, which is should always be and the following 
            //below code fails because of some error returned by the server ( like invalid email or bad password )
            //this is okay, because the next attempt will still use the same silent account that was already created.

            //Now add our username & password.
            PlayFabClientAPI.AddUsernamePassword(new AddUsernamePasswordRequest()
            {
                Username = !string.IsNullOrEmpty(Username) ? Username : result.PlayFabId, //Because it is required & Unique and not supplied by User.
                Email = Email,
                Password = Password,
            }, (addResult) =>
            {
                if (OnLoginSuccess != null)
                {
                    var currentPlayer = new PlayerInfo
                    {
                        EntityToken = result.EntityToken.EntityToken,
                        PlayFabId = result.PlayFabId,
                        SessionTicket = result.SessionTicket
                    };
                    //Store identity and session
                    _playFabId = result.PlayFabId;
                    _sessionTicket = result.SessionTicket;
                    
                    

                    //Override the auth type to ensure next login is using this auth type.
                    
                    AuthType = Authtypes.EmailAndPassword;
                    Debug.Log("Before updating email");
                    AddOrUpdateContactEmail(Email);
                    LinkDeviceId();
                    Debug.Log("After Updating email");
                    //Report login result back to subscriber.
                    OnLoginSuccess.Invoke(result);
                }
            }, (error) =>
            {
                if (OnPlayFabError != null)
                {
                    //Report error result back to subscriber
                    OnPlayFabError.Invoke(error);
                    Signals.Get<PlayFabErrorSignal>().Dispatch(error.Error);
                    
                }
            });

        });
    }

However I get the following error.

/Client/AddUsernamePassword: User already linked to a different account



When the device isn't linked to any account, the signing up successfully works. I even have a sign out feature which basically unlinks the user. However how can I unlink an account before running this

AddAccountAndPassword() function.

Authentication
10 |1200

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

anudeep avatar image
anudeep answered

@Rick Chen I unlink the device upon signing out. However there are very few cases especially when I am testing, I don't tend to log out and just uninstall the device. Upon reinstalling and checking account creation, is when i found this issue. Yes If i unlink the device id i am able to create the account, otherwise I get an error saying the player is linked to another account.
The solution I am looking for is, even if the device id is linked to another account, I silently authenticate into a new account, after unlinking from the previous one. I have tried to unlink just before Silently authenticating. But that doesn't seem to solve it.

3 comments
10 |1200

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

Rick Chen avatar image Rick Chen ♦ commented ·

It doesn't make sense to me. The point of silently login a user is to bind an account with the device id so that the user can login to that account with the device id. What is the point of creating new account with the same device id every time the user silent login?

If you just want to register a bunch of accounts with username and password for whatever reason, you can just use the RegisterPlayFabUser API instead, no device id is needed.

0 Likes 0 ·
anudeep avatar image anudeep Rick Chen ♦ commented ·

In addition to previous comment, I haven't mentioned that I am linking the device id upon players request to remember me. i.e upon toggling remember me only, the user's device gets linked in, so everytime they open the device, they are silently authenticated into their account but silently.
Even when the device id is linked to another account, it gets unlinked from that and gets linked to the account for which the player types in their credentials. Is there some other way I should be implementing the Remember me functionality?
Now, because of the remember me, I found myself in a situation where the sign up doesn't work when the device is already linked to an account.

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ anudeep commented ·

In this case, you can implement the login flow in this way:

  1. When player starts game, use LoginWithCustomID API to login. (CreateAccount set to false such that the player does not create account in this way).
  2. If login failed, which means this device id hasn’t been linked to any account yet, ask the player to LoginWithEmailAddress first. If they don’t have a PlayFab account, they can choose register account with RegisterPlayFabUser API. If the player choose “remember me”, after the player login/registered with username password, use LinkCustomID API to link the account with their device id.
  3. Login successfully means the player has linked the account with device id, no further action needed (no need to AddUsernamePassword, since the account already has username and password)
  4. If the player unselects “remember me” during game (after they logged in), you can use UnlinkCustomID API to remove the device id from their account. Next time they start game they will go to step 2.
0 Likes 0 ·
Rick Chen avatar image
Rick Chen answered

After you silently register an account, you only need to call the AddUsernamePassword API for that account once to add username and password to that account. Once added, you don’t need to call it again. You can check whether an account is newly created by checking the NewlyCreated parameter in the login result.

4 comments
10 |1200

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

anudeep avatar image anudeep commented ·

I didn't understand what this is supposed to mean. In the above code I do have AddUsernamePassword API for that account.
Not sure if you understood my problem as well. When I am silently authenticating, it is authenticating into an already existing account with which the device id has been linked from a previous session.

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ anudeep commented ·

I assume you are using LoginWithCustomID API with your device id in your silent authenticating method. This API takes a custom id (in this case, your device id) as a secret to login/register an account. After first time login with that device id, the created account will bind with that device id. And calling LoginWithCustomID API with that device id will login to that binding account.

0 Likes 0 ·
anudeep avatar image anudeep Rick Chen ♦ commented ·

But my issue is that the Device id is already linked to another account. So upon Silently authenticating for creating a new account, I am logging in to an old account which already exists. I have implemented Unlinking the device id upon signing out. But is there any way even if the device id of the device through which I am creating a new account is already linked to an old account, make a new guest account and AddUsernamePassword to that new guest account?

Below is my code for LoginWithCustomID

0 Likes 0 ·
Show more comments

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.