Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 393
quarks Avatar asked Oct 26 '25 23:10

quarks


1 Answers

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
}
like image 175
ThierryC Avatar answered Oct 28 '25 13:10

ThierryC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!