question

Kim Strasser avatar image
Kim Strasser asked

Azure Functions: How can I find out if a key/value pair exists in player internal data?

I use this code in my Azure function to get the stored password recovery email token. The token is automatically saved when the player clicks on the link in his password recovery email.

var getUserInternalDataResponse = await adminApi.GetUserInternalDataAsync(new PlayFab.AdminModels.GetUserDataRequest(){
			PlayFabId = playfabid,
			Keys = new List<string> () {"ResetPasswordToken"}
		    });
if (getUserInternalDataResponse.Error != null)
{
    log.LogInformation($"Error: = {getUserInternalDataResponse.Error.Error}");
    var errors = OnPlayFabError(getUserInternalDataResponse.Error, language);
    errorline1 = errors[0];
    errorline2 = errors[1];
    errorline3 = errors[2];
    errorline4 = errors[3];
    return new Result
    {
        FunctionSuccessful = false,
        Errorline1 = errorline1,
        Errorline2 = errorline2,
        Errorline3 = errorline3,
        Errorline4 = errorline4
    };
}
else
{
    var tokenId = getUserInternalDataResponse.Result.Data["ResetPasswordToken"].Value;
    log.LogInformation($"tokenId = {tokenId}");
    // change password here ...
}

But when the player calls my Azure function "ChangePasswordUpdate" without having clicked on the link in his password recovery email, then the player gets the following error message in my game:

"Invocation of cloud script function ChangePasswordUpdate failed"

The problem is, the player doesn't know what he did wrong when I display this error message in my game. Therefore, I want to find out in my Azure function if "ResetPasswordToken" exists in internal data. If not, then I want to display this custom error message in my game:

We have send you an email. You need to click on the link in this email before you can change your password.

How can I find out in my Azure function if "ResetPasswordToken" exists in player internal data so that I can display my custom error message in my game when the player forgot to click on the link?

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.

1 Answer

·
Seth Du avatar image
Seth Du answered

You may simply specify the required key ID in the request and check the returned callback if a nonempty value exists. For example, in the request I want to retrieve the kvp “preferences”:

{ 
"PlayFabId": "xxxxxxxxxxx", 
"Keys": [ 
"preferences"  ]
}

While the returned callback doesn’t contain any value, and it means the kvp doesn’t exist.

{
    "code": 200,
    "status": "OK",
    "data": {
        "PlayFabId": "xxxxxxxxxxx",
        "DataVersion": 0,
        "Data": {}
    }
}
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.