Masterkey in a beforeSave

I’ve just changed the permission of CLP to read only for a collection that is populated from a contract sync event.

On this collection I’ve a beforeSave to add more fields once the row is created.

I do some “set” like
request.object.set("playerName", player.get("name"));

I’m receiving an error from the console like this

2022-05-31T14:44:24.268Z - Error: Permission denied for action update on class TokenSalesStatus.
at Function.validatePermission (/moralis-server/lib/Controllers/SchemaController.js:1512:11)
at SchemaController.validatePermission (/moralis-server/lib/Controllers/SchemaController.js:1517:29)
at /moralis-server/lib/Controllers/DatabaseController.js:542:63
at processTicksAndRejections (node:internal/process/task_queues:96:5)

Since is a permission error, how can I save with the masterkey in a newly created row in the collection?

I’m saving at the end of the “set” like this with the master key, but it seems not working, {useMasterKey:true});

Thank you

I don’t think that you should use .save at the end, it should be enough only to use .set
this was the first approach?

I’ve seen that it was working correctly only with set because I had CLP at read / write / add field

As soon as I’ve changed it to read only, the error above was raised and I’m trying to figure out how I can use the masterKey on it (or any other approach)

I’ve thought, since is something that is coming from a contract sync event, and was created before the nitro update, should I add “coreservices” user to perform actions on it since CLP is set to read only?

you should add coreservices role to CLP in case that it is not already there

1 Like

ok thanks, with nitro this is added by default with collections created with synced contracts?

it should be added automatically for a nitro server, that coreservices role to CLP for the tables where events sync

1 Like