question

Kim Strasser avatar image
Kim Strasser asked

How can I find out if the contact email VerificationStatus is confirmed in CloudScript?

I get an error message when I want to find out if the players contact email address is confirmed.

What is wrong with my code?

var playerData = server.GetPlayerProfile( 
		{ 
			"PlayFabId": currentPlayerId, 
			"ProfileConstraints":
			{"ShowContactEmailAddresses":true
			}
		})
		
if (playerData.Error == null)
{ 
	var contactEmailAdresses = playerData.PlayerProfile.ContactEmailAddresses;
	var playeremail = "";
 	var emailVerificationStatus = null;
  	if ((contactEmailAdresses != null) && (contactEmailAdresses.length > 0))
  	{
      		emailVerificationStatus = contactEmailAdresses[0].VerificationStatus;
      	    	if (emailVerificationStatus != null)
      	    	{
      	      		if (emailVerificationStatus == PlayFab.ClientModels.EmailVerificationStatus.Confirmed)
      	        		playeremail = contactEmailAdresses[0].EmailAddress;
      	      		else
      	        		checkemail = "Current contact email is not verified.";
      	    	}
      	    	else
      	     		checkemail = "Current email is not verified.";
        	}
        	else
		  	checkemail = "No valid email found.";
	}
	else
		checkemail = "Error";

Error:

  "Error": {
            "Error": "JavascriptException",
            "Message": "JavascriptException",
            "StackTrace": "ReferenceError: PlayFab is not defined\n    at handlers.CheckContactEmail (E5E2C-main.js:5128:45)\n    at Object.invokeFunction (Script:116:33)"
        }
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

·
Rick Chen avatar image
Rick Chen answered

I noticed that in line 19 of your code snippet 1, there is “PlayFab.ClientModels.EmailVerificationStatus.Confirmed”. In CloudScript, the “PlayFab” is not defined as the Error explains. To determine whether the status is confirmed, you could write:

if (emailVerificationStatus == “Confirmed”)

The available Status values can be found in: https://docs.microsoft.com/en-gb/rest/api/playfab/server/account-management/getplayerprofile?view=playfab-rest#emailverificationstatus

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.