1

Hello here is my cloud code

Parse.Cloud.beforeSave(Parse.User,async (request)=>{
      const user = request.object;
      const t = user.get('tProfile');
      const s = user.get('sProfile');
      if (!t && !s) {
        user.setACL(new Parse.ACL(user));
      }else{
        console.log('Old user detected');
      }
    });

As you can see I am trying to set Acl for a new user signing up with a before save handler, but the error that I get is UserID must be a string. So my question is how can I set an acl for a new user who is just signing up ? Thankyou

Tanzim Chowdhury
  • 3,020
  • 2
  • 9
  • 21
  • Can you share the complete error stack? BTW, why don't you send the ACL from client? – Davi Macêdo Feb 21 '20 at 15:59
  • TypeError: userId must be a string. at ParseACL._setAccess (/usr/src/app/node_modules/parse/lib/node/ParseACL.js:165:13) at ParseACL.setReadAccess (/usr/src/app/node_modules/parse/lib/node/ParseACL.js:238:10) at new ParseACL (/usr/src/app/node_modules/parse/lib/node/ParseACL.js:57:14) at /usr/src/app/data/cloud/main.js:8:18 at /usr/src/app/node_modules/parse-server/lib/triggers.js:565:23 at processTicksAndRejections (internal/process/task_queues.js:89:5) – Tanzim Chowdhury Feb 21 '20 at 16:26
  • Do you mean set acl and then use **saveInBackground()** ? I'm not doing that because im following the security guidelines of back4app which says the keep only **Create** and **Get** permission for Users table so **Update** is only allowed through cloud code . Hence I want to set up the Acl as soon as a user signs up. Im guess user objects which have not been created yet dont have an object ID on before save handler and thats why im getting this error ? – Tanzim Chowdhury Feb 21 '20 at 16:34
  • I belive in beforeSave if user does not exist therefore id of user is undefined so that is why you are getting this error. – Suat Karabacak Feb 21 '20 at 17:40
  • Yes. That's probably the reason of your problem. But since you have enabled Create, you can send the ACL setup when you are saving the user for the first time, without using the trigger. – Davi Macêdo Feb 21 '20 at 19:03
  • And how exactly do I do that ? Sorry if it's rookie question but bit confused as to how it should be sent – Tanzim Chowdhury Feb 21 '20 at 20:58
  • You can set user's ACL as you mentioned in question user.setACL(new Parse.ACL(user)); in your client SDK. Which platform you are using for your client app ? – Suat Karabacak Feb 21 '20 at 21:26
  • Yea I will do that , Client SDK is android – Tanzim Chowdhury Feb 22 '20 at 05:33

1 Answers1

1

So i finally found a way to do so. In the Before save handler just use this code :)

    Parse.Cloud.beforeSave(Parse.User, async (request) => {
       var newOjb = request.object;
       if (!request.original) {
             newOjb.setACL(new Parse.ACL(Parse.User.current()));
        }
    });
Tanzim Chowdhury
  • 3,020
  • 2
  • 9
  • 21