javascript - Check if User has Role - Parse Cloud Code -


writing parse cloud function (which uses parse javascript sdk) , having trouble checking see if current user has role "admin". i'm looking @ web view of role class , role name "admin" exists, if click "view relations" users, shows current user. doubt should matter, "admin" role , current user user role. lastly, "admin" role has acl of public read, shouldn't causing issues either.

code follows:

... 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;     } ... 

this results in following in log:

before test: auth = false

after test: auth = false

give shot:

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 start... in success 1 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 admin role");     } }).then(function() {     console.log('after test: auth = ' + authorized); }); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -