Restricting users from updating field in User class

hi there in my User class i have an extra field called paid
that is by default false
i wanna restrict users from updating this field to true how can i do that

V4.4.0+

Parse.Cloud.beforeSave(Parse.User, () => {
  // any additional beforeSave logic here
}, {
    fields: {
      paid: {
        default: false,
        constant: true
      },
    },
});

Before V4.4.0:

Parse.Cloud.beforeSave(Parse.User, ({object, original = new Parse.User(), master}) => {
  if (master) {
    return;
  }
  object.set('paid', original.get('paid') || false);
});

Then you can update paid using masterKey.

2 Likes