I was looking for some suggestions re. creating pointers on user.signUp via cloud code.
My problem is that as request.object (i.e request.user because it’s a trigger on beforeSave) has no objectId, so I can’t set ACLs for my pointer.
If I use it on afterSave, the trigger resolves before pointer.save is set.
Here’s my code:
const user = new Parse.User();
user.set('businessName','xx');
await user.signUp();
// I want to be able to call user.get('business') here and it be a pointer with ACLs set.
...
cloud:
// I can't user beforeSave because object.id isn't defined on new objects, so I can't set ACL for business object
Parse.Cloud.afterSave(Parse.User, async ({object}) => {
if (!object.existed()) {
const acl = new Parse.ACL(object);
object.setACL(acl);
const business = new Parse.Object('Business');
business.set('name',object.get('businessName'));
object.unset('businessName');
business.set('admin',object);
const businessACL = new Parse.ACL(object);
business.setACL(businessACL);
await business.save(null,{useMasterKey:true});
object.set('business',business);
}
});
I know that I can do it on the frontend, but I’m trying to keep my SDK code as simple and clean as possible.
Thanks for the response! This has no affect on the object on the frontend. Even when I add the code you specify, the object returned from signup / user.get('business') is still null.
I am not sure the pointer fields will be included, but it should be defined and having an id. Would you mind to also test using the REST API? Maybe it is somethinng in the JS SDK.
@davimacedo you were right, the beforeSave trigger for the Business class was preventing save of the object, so the return statment was never called. Thank you!