Skip to content

Instantly share code, notes, and snippets.

@chengscott
Created July 25, 2015 05:50
Show Gist options
  • Select an option

  • Save chengscott/1909f155695b924ca683 to your computer and use it in GitHub Desktop.

Select an option

Save chengscott/1909f155695b924ca683 to your computer and use it in GitHub Desktop.
Parse Cloud Code - new user add to a role
Parse.Cloud.afterSave("_User", function (request, response) {
Parse.Cloud.useMasterKey();
var user = request.object;
query = new Parse.Query(Parse.Role);
// add user to the role named "General"
query.equalTo("name", "General");
query.first({
success: function (object) {
object.relation("users").add(user);
object.save();
response.success("The user has been authorized.");
},
error: function (error) {
response.error("User authorization failed!");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment