Hello everyone,
I’m not being able to use the function “destroy” with master key, it keeps saying “permission denied” when I’ve my CLP just with read access.
I already tried obj.destroy(null, {useMasterKey:true}) and also obj.destroy({useMasterKey:true}) and none of them work.
Here is my cloud function:
Moralis.Cloud.beforeSave("PiecesSaleCancelled", async (request) => {
if (!request.object.get("confirmed")) return;
const tokenId = request.object.get("tokenId");
const item = await new Moralis.Query("PiecesOnSale")
.equalTo("tokenId", tokenId)
.first({ useMasterKey: true });
const modeOnSale = await new Moralis.Query("Mode").equalTo("Id", 2);
const modeAvailable = await new Moralis.Query("Mode")
.equalTo("Id", 1)
.first();
const robotsOnSale = await new Moralis.Query("MintedPieces")
.matchesQuery("Mode", modeOnSale)
.equalTo("TokenId", +tokenId)
.first();
robotsOnSale.set("Mode", modeAvailable);
robotsOnSale.save(null, { useMasterKey: true }).then((robot) => {
logger.info("Piece " + tokenId + " Mode set from On Sale to Available");
});
if (item) {
item.destroy({ useMasterKey: true }).then(
() => {
logger.info("Piece " + tokenId + " removed from sale with success");
},
(error) => {
logger.error("PiecesSaleCancelled ERROR: " + JSON.stringify(error));
}
);
}
});
Does anyone have any idea why and what to do?
Obs: I’ve “Client Class Creation” disabled and all CLP just with read access.