Object not found when not using master key

Hey o/, iā€™m tryng to make one validation in cloud code and edit an object but iā€™m getting the response: object not found.

The query return he value but is not saving.

This is my code:

Moralis.Cloud.define("cancelAuction", async (request) => {
  const auctionId = request.params.auctionId;

  const auctionClass = Moralis.Object.extend("Auction");
  const queryAuction = new Moralis.Query(auctionClass);
  queryAuction.equalTo('objectId', auctionId);
  let auction = await queryAuction.first();

  if(!auction) {
    throw "Auction not found"

  if(auction.get('lastValidTransaction').get('action') === 2) {
    auction.set('status', 4)
    return await auction.save()

  throw "Auction already have an interaction";

I saw that when i use the master key it works. When looking for the ACL permissions the current user of the request have permission to write that object.

I think that you need to use master key, this cloud function may not run in the context of a user, if you would be using this in front end directly then it would run in the context of that user.

1 Like