Sign In Register

How can we help you today?

Start a new topic
Answered

Edits or limits on 'built in' client api requests?

Obviously with my own events, I can put whatever checks/restrictions on inbound data as I want in the cloud code - but with events like ChangeUserDetailsRequest (GameSparks provided) - are there any edits/limits on the values sent in - specifically displayName?


I see that I can add my own code to the ChangeUserDetailsRequest request - is that code executed AFTER the functionality that GameSparks provides or BEFORE?   If it was before, I could possibly add some edit restrictions (length, bad language check, etc) and then either generate error condition or 'scrub' the value before it was persisted.


Thoughts?


(Obviously - I could create my own field in in Player or my own collection and my own events to populate - but displayName seemed 'correct' and already provided...)


Thanks in advance!!





Best Answer

Hi Jeff,


You can use 'throw' to stop a request in it's tracks and send the appropriate error. A simple example using some Cloud Code in the RegistrationRequest would be as follows.

 

//get the password the user just supplied
var userPassword = Spark.getData().password;

//if the password is blank, throw an "Invalid Password" error
if(userPassword == ""){
    throw "Password Invalid";
} 

   

With this you could add your own checks in the RegistrationRequest and throw appropriate errors to the user where needed. Hope this helps.


Thanks,

Liam


Answer

Hi Jeff,


You can use 'throw' to stop a request in it's tracks and send the appropriate error. A simple example using some Cloud Code in the RegistrationRequest would be as follows.

 

//get the password the user just supplied
var userPassword = Spark.getData().password;

//if the password is blank, throw an "Invalid Password" error
if(userPassword == ""){
    throw "Password Invalid";
} 

   

With this you could add your own checks in the RegistrationRequest and throw appropriate errors to the user where needed. Hope this helps.


Thanks,

Liam

Exactly what I was looking for....thanks!!  

(mark as 'Answered' please)

Login to post a comment