I am looking for a way to trigger a Parse Cloud Job when a user register in my platform. This Job will set his role. Is it possible? I have try with this code but it is never triggered
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.useMasterKey();
console.log('launch cloud request');
if (request.master === false) {
console.log('not mastered');
var query = new Parse.Query(Parse.Role);
query.equalTo('name', 'default');
query.first({
success: (default) => {
var defaultRelation = default.relation('users');
defaultRelation.add(request.object);
default.save();
},
error: (err) => console.error(err)
});
}
});
I think Parse.Cloud.useMasterKey() is deprecated at this time,
You can do that
Parse.Cloud.afterSave(Parse.User, function(request) {
console.log("Parse.Cloud.afterSave: ");
request.log.info("Parse.Cloud.afterSave: "); // For back4app user
});