写一个 Parse Cloud Function (使用 Parse Javascript SDK )我无法检查当前用户是否具有 Angular 色“Admin”。我正在查看 Role 类的 Web View ,并且存在一个名为“Admin”的 Angular 色,如果我单击用户的“查看关系”,它会显示当前用户。我怀疑这应该重要,但“管理员”是唯一的 Angular 色,当前用户是唯一具有 Angular 色的用户。最后,“Admin” Angular 色有一个 Public Read 的 ACL,所以这也不应该导致任何问题。
代码如下:
...
var queryRole = new Parse.Query(Parse.Role);
queryRole.equalTo('name', 'Admin');
queryRole.equalTo("users", Parse.User.current());
queryRole.first({
success: function(result) { // Role Object
var role = result;
role ? authorized = true : console.log('Shiet, user not Admin');
},
error: function(error) {
console.log("Bruh, queryRole error");
}
})
console.log('After test: Auth = ' + authorized);
if (!authorized) {
response.error("You ain't no admin, measly user");
return;
}
...
这会在日志中产生以下结果:
Before test: Auth = false
After test: Auth = false
最佳答案
试一试:
var authorized = false;
console.log('Before test: Auth = ' + authorized);
var queryRole = new Parse.Query(Parse.Role);
queryRole.equalTo('name', 'Admin');
queryRole.first({
success: function(result) { // Role Object
console.log("Okay, that's a start... in success 1 with results: " + result);
var role = result;
var adminRelation = new Parse.Relation(role, 'users');
var queryAdmins = adminRelation.query();
queryAdmins.equalTo('objectId', Parse.User.current().id);
queryAdmins.first({
success: function(result) { // User Object
var user = result;
user ? authorized = true : console.log('Shiet, user not Admin');
}
});
},
error: function(error) {
console.log("Bruh, can't find the Admin role");
}
}).then(function() {
console.log('After test: Auth = ' + authorized);
});
关于javascript - 检查用户是否有角色 - 解析云代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29177755/