Created
July 25, 2015 05:50
-
-
Save chengscott/1909f155695b924ca683 to your computer and use it in GitHub Desktop.
Parse Cloud Code - new user add to a role
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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