Monday, 15 March 2010

javascript - Parse Error: "Can't modify username in the before save trigger" and "Validation Failed" -



javascript - Parse Error: "Can't modify username in the before save trigger" and "Validation Failed" -

i trying save user (pull info facebook , add together columns, have nothing parse username) in parse's beforesave trigger in cloud, i'm getting next error @ ios app while registering:

can't modify username in before save trigger

it's pretty self explanatory, right? little fact don't modify username anywhere, neither in trigger, cloud function, or client-side in ios app. don't access or utilize it. user created cloud-code added fields though. error:

validation failed

then, user object doesn't seem save. both errors occuring randomly, same test user. i've searched whole project word "username" sure i'm not setting somewhere either straight or indirectly. not saving anywhere. parse bug, or missing obvious? here total code:

parse.cloud.beforesave(user, function(request, response) { var user = request.object; if(typeof user.get("nickname") == "undefined" || user.get("nickname") == null){ var randomnick = "user " + math.floor(math.random() * 1000000); user.set("nickname", randomnick); } if(user.get("facebookid") == undefined){ var token = user.get('authdata')['facebook']['access_token']; parse.cloud.httprequest({ url: 'https://graph.facebook.com/v2.1/me?fields=id,gender,name&access_token=' + token, success: function(httpresponse) { var responsedata = httpresponse.data; user.set("facebookid", responsedata.id); user.set("realname", responsedata.name); if(responsedata.gender !== undefined){ user.set("gender", responsedata.gender); } var acl = new parse.acl(); acl.setpublicreadaccess(false); user.setacl(acl); user.save(null, { usemasterkey:true, success: function(){response.success()}, error: function(o,e){response.error("error: " + e)} }); }, error: function(httpresponse) { console.error('request failed response code ' + httpresponse.status); } }); }else{ response.success(); } });

the problem trying save object in beforesave trigger; don't need save it, need modify , phone call response.success() allow parse.com know go on save operation. error getting due fact it's trying create same user twice - although that's guess.

see https://parse.com/docs/cloud_code_guide?language=javascript#functions-onsave more information.

remove user.save() phone call , phone call response.success().

javascript parse.com cloud-code

No comments:

Post a Comment