Dev TeamSolar avatar image
Dev TeamSolar asked

Restore existing account on new device after frictionless login

On startup, my game logs the user in with LoginWithAndroidDeviceID (or LoginWithIOSDeviceID) automatically with CreateAccount set to true and the game proceeds to the main menu. Say the user links their Facebook account as a recoverable login option. If they get a new device and want to log into their existing account with their Facebook account linked, how would I do that with my current login flow? So the player starts up the game on their new device and a PlayFab account is automatically created and logged in with the new device ID, but they want to restore and login to their previous existing account on their new device. How can I log into another existing account if they are currently logged into the account that was created on anonymous login? I know I will want to link the new device ID to the existing PlayFab account with the Facebook account already linked, but what will happen to the PlayFab account that just got created?

Player DataAccount Managementgame manager
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

LoginWithIOSDeviceID and LoginWithAndroidDeviceID are anonymous login mechanisms. It’s not suitable for restoring accounts. So, if we want to restore an existing account on a new device, we shouldn’t create a new account with a new deviceID. Actually, you have linked players’ accounts with Facebook. You can let players use LoginWithFacebook to log in existing accounts. It is a recoverable login mechanism.

So, your current login flow seems to lose such a “log in with an existing account” option. It's not so flexible to always use anonymous login mechanisms when players log in to the game whether or not they have an existing account. You can add a "log in with an existing account" button in your game login panel to let players choose. When they choose “log in with an existing account”, you can let players use LoginWithFacebook to log in existing accounts. If so, your players can restore existing accounts on new devices.

If you want to learn more about LoginWithFacebook, you can check Tutorials Setting up PlayFab authentication using Facebook and Unity and API references here.

10 |1200

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

Seth Du avatar image Seth Du ♦ commented ·

Also, here is few things you need to know @Dev TeamSolar:

  • We suggest developers to append random-generated string to the original device ID in a safety concern. Usually we don't want anyone to sign in the same account after the owner of device is changed. You may store the modified device ID in the client until the app data or system is wiped.
  • Since now the device ID is unique, there are basically 2 scenarios for your requirements:
    1. Before the Login. You may add a “log in with an existing account” option before the anonymous login like @Sarah Zhang has mentioned. Provide a button that can directly login with Facebook ID.
    2. After the anonymous login. You won't worry about the newly created account since it is blank and device ID is unique. You may also simply provide a button like "login with Facebook" and forget about the newly created account. PlayFab won't care too much about orphan accounts, and you can craft your own way to delete them once a while.
0 Likes 0 ·
Seth Du avatar image Seth Du ♦ commented ·

PS. If you have concern about the device ID of newly created account. You can try:

  • Login anonymously, using Device_ID_2
  • Player click Login into Facebook, after the authentication is successfully done and client has received the access token
  • Store the Device_ID_2 and call Unlink API like UnlinkAndroidDeviceID
  • Use Facebook access token to login
  • Call Link API like LinkAndroidDeviceID

This may make sure all the device IDs are linked to the same account but I can say it is quite unnecessary.

0 Likes 0 ·
jamilkassis avatar image jamilkassis Seth Du ♦ commented ·

Hi, I am facing a problem regarding this matter. Let me explain:

On Device A: I logged in anonymously using device id, then I created an email account (AddUsernamePassword API). Then The device id and email are linked.

On Device B: I logged in anonymously and logged in using the email account created above and force link with this device ID.

I cleared all data on Device A and logged in anonymously, then the playfab account is relinking the device A id with the email account created above ( I am not logging in using email). How is that?

Every step I mentioned above is completed successfully but what is happening here? why it is linking to the email address if it is anonymous login only? I didn't check a third device yet.

0 Likes 0 ·
Daniel Hornkvern avatar image Daniel Hornkvern jamilkassis commented ·

Did you find a solution to this?

0 Likes 0 ·

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.