question

oglazirin avatar image
oglazirin asked

Adding email, password and displayname from CloudScript

Hi there!

A new player launches my game for the first time, and then behind the scenes he gets registered in PlayFab with his DeviceID. Later on the player should have an option to add email, password and displayname to his account.

Is it possible to do this via CloudScript?

I know that Client API has AddUsernamePasswordRequest and UpdateUserTitleDisplayNameRequest, but I would like to only make a single request to update everything at once. Server API doesn't offer the same methods, I guess this is why the following code doesn't work:

handlers.registerPlayer = function (args, context) 
{
    server.AddUsernamePassword({
        Email: args.email,
        Password: args.password,
    });

    server.UpdateUserTitleDisplayName({
        DisplayName: args.displayName
    });
}

Are there any other solutions?

Thank you!

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

·
brendan avatar image
brendan answered

Those calls are only available in the Client API currently, though we are planning on making more of the Client calls available in the Server API in a future update. One thing you can do is to add a Username in the first call as well, as that would also give you a name for the player that you could use. But I wouldn't worry about having two make two calls from the client when setting up the player account.

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.

oglazirin avatar image oglazirin commented ·

Thank you!

0 Likes 0 ·
oglazirin avatar image oglazirin commented ·

Hello @Brendan!

Turned out there is a limitation when using AddUsernamePasswordRequest. I want to only add Email and Password to an existing PlayFab account but the username is also required.

I don't want my users to have usernames in addition to display names. First of all, having an email is enough to distinguish between users. Secondly, I really don't want to ask our users to fill in an additional field during the registration. Some users might abandon the registration process because it requires too much input. Also for some people the difference between username and display name might be unclear.

Are there any way to add an email with a password but without a username?

I was thinking about removing '@' and '.' characters from each email and using it as a username. Do you think this is a good idea?

Thank you!

0 Likes 0 ·
brendan avatar image brendan oglazirin commented ·

Correct. To set up an account with Email and Password only, you would need to create it with RegisterPlayFabUser, passing in those two elements (and the Title ID).If you want to use one of the zero-friction methods to create the account (Device ID, Custom ID, etc.), and then add an email/password later, you would currently need to use AddUsernamePassword, and you would need to add a username. But technically, you could just randomly generate that, or use the player's PlayFab ID (since that's guaranteed to be unique). Stripping an email address definitely wouldn't be advisable, since you'd have too many duplicates (and the username must be unique in that call). We'll be adding more ways to work with user accounts in a future update, including being able to add only email, etc., though we don't have a date we can provide for that just yet.

1 Like 1 ·
oglazirin avatar image oglazirin brendan commented ·

Using PlayFab ID for sounds like a much better idea :) Thanks!

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.