question

pmaloka avatar image
pmaloka asked

How do I RegisterPlayFabUser from CloudScript,How do I register a new user from inside cloudscript

I am trying to have a user be able to create a sub-user. To do this, I need to create the new user AND link the new user and "parent" user together. The client (unity) is building the RegisterPlayFabUserRequest just fine, and passes that to my cloud script. The "Parent" user is signed in, so CloudScript has access to the "parent" playerId. Cloud script needs to register the new "child" account with the provided info (from the request), then set a parentID field in the new account to point to the "parent" account, AND set the childID field in the "parent" account to the player ID of the newly created "child" account. All of this is in place, however, I can't find the CloudScript version of PlayFabClientAPI.RegisterPlayFabUser. Once I have that call, I can easily create the new user, grab the playerId from the register response, and save it in the parent user data. Again, the question is, how do I call RegisterPlayFabUser from within cloudscript? I don't want to issue multiple calls from the client to the server, Yes, I know I could do a register call, followed by calls to link the parent to the child, and the child to the parent, but issuing 3 calls that are not guaranteed to all make it is asking for trouble with dangling accounts.

Please keep in mind that I'm no JavaScript expert, so please provide as much detail as possible.

,

I am trying to have a user be able to create a sub-user. To do this, I need to create the new user AND link the new user and "parent" user together. The client (unity) is building the RegisterPlayFabUserRequest just fine, and passes that to my cloud script. Cloud script needs to register the new account with the provided info, then set a parentID field in the new account to point to the calling account, AND set the childID field in the calling account to the player ID of the newly created account. All of this is in place, however, I can't find the CloudScript version of PlayFabClientAPI.RegisterPlayFabUser.

CloudScript
10 |1200

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

pmaloka avatar image
pmaloka answered

Thanks for getting back to me. I had suspected that there was no way to implement this in CloudScript in a single call, but I wanted to make sure. Looks like I will have to implement some kind of hybrid client/server system. It sure would have been easier to have it all done atomically on the server, but, oh well.

To answer your question about how this is being used, the idea is that a "parent" account can purchase a subscription, and up to 3 "family" accounts can be use that subscription (like with my family Spotify or Netflix accounts where I have a paid subscription, and my wife has her account "connected" to my account. As long as my account is paid, she gets the service as part of my account).

I agree with the idea of using the player read-only data - that was where I have already implemented the linkages. It is in read-only so that the information is available to the UI ("parent" can see linked "children" and "remove" them from the account). All needed functionality had been implemented, except for the actual server side register call.

Thanks again for getting back to me so promptly!!!

1 comment
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 ·

Even if registering account can be done on CloudScript, it is not secure and not recommended.

Thank you for sharing the detail, the player read-only data seems good in your scenario.

0 Likes 0 ·
Rick Chen avatar image
Rick Chen answered

I am afraid that there is no way to register a PlayFab Account in CloudScript. As you mentioned, you could do it on your client-side.

I understand that there could be trouble of dangling accounts when the parent account and child account are registered but saving the PlayFabId failed. However, apart from the PlayFabId, the Username or Email used in RegisterPlayFabUser API is also unique identifier, you can store the username or email to corresponding account user data. Then you can retrieve the PlayFabId with the username or email by using GetAccountInfo API.

Could you tell me the detail about how the child account is used and what it can do comparing with parent account?

If you don’t want to allow the player to alter their sub-user account ID saved in parent account, I suggest using server APIs in CloudScript to store the ID in Player Read-Only Data or Player Internal Data. Overall, that is using client APIs only for registering account and using server APIs to manage the player data. You could refer to Player Data to see the difference among data modes.

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.