简体   繁体   English

Parse.com安全角色未保存

[英]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. 这是我第一次在Parse中扮演安全角色,我相信我要做的事情很简单。 I want to create a new security Role after I signup a new user using the afterSave trigger in CloudCode. 在CloudCode中使用afterSave触发器注册新用户后,我想创建一个新的安全角色。

I've verified that this is being called and the roleName is correct, but nothing is being saved in the data browser. 我已验证正在调用此函数,并且roleName正确,但是没有在数据浏览器中保存任何内容。 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. 我希望如果试图使用无效字符进行保存,Parse会抛出错误,但是现在问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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