Is it possible to check inside beforeSave method if Parse master key is used?

742 views Asked by At

It is important in my app to have no duplicates so I have this code:

Parse.Cloud.beforeSave("Thing", function(request, response) {
    var newEntryThing = request.object;
    var thingId= newEntryThing.get("thingId");
    var queryThings= new Parse.Query("Thing");
    queryThings.equalTo("thingId", thingId);

    queryThings.first({
        success: function(results) {
            if(results) {
                response.error({errorCode:400,errorMsg:"Thing already exist"});
            } else {
                response.success();
            }
        },
        error: function(error) {
            response.success();
        }
    });
});

So far this works for that purpose, the problem is that even Parse dashboard cannot update this class anymore, due to the logic. What I am thinking is to check first if the method is called using masterkey if yes, then this logic will be bypassed and would allow update. Is it possible to check in this beforeSave method if Parse master key is used?

1

There are 1 answers

0
ThierryC On BEST ANSWER

To check inside beforeSave() if maskerkey is used (or if you are making the request from the dashboard) try to add this condition in your cloud code :

if (request.master){
    . . .//dosomething
}