简体   繁体   中英

Parse.com security Role not saving

This is my first time playing around with security roles in Parse and I believe what I'm trying to do is fairly simple. I want to create a new security Role after I signup a new user using the afterSave trigger in CloudCode.

I've verified that this is being called and the roleName is correct, but nothing is being saved in the data browser. I feel like I'm missing something pretty basic here for this not to be working - is there a setting somewhere I need to turn on?

Parse.Cloud.afterSave(Parse.User, function(request, response) {
 var user = request.object;
 if (user.existed()) { return; }

 var acl = new Parse.ACL();
 acl.setPublicReadAccess(false);
 acl.setPublicWriteAccess(false);

 var roleName = user.get("email");

 Parse.Cloud.useMasterKey();
 var companyRole = new Parse.Role(roleName, acl);
 console.log("Role = " + companyRole);
 companyRole.save();

});

Found the solution. In Parse, you the name for a Role can only contains letters, numbers, and underscore. I was trying to set the role name as an email address, which contains '@' and '.'

I did a replace on these characters before I saved the name and worked perfectly. I wish Parse would've thrown an error if trying to save with invalid characters but problem solved now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM