问题
It woked while ago, but suddenly stopped. Looks like it has something to do with session migration but I don't know why and how to deal with it.
So I've got simple cloud code sample:
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
It works fine naturally.
And I want to run it from afterSave trigger like this:
Parse.Cloud.afterSave(Parse.User, function(request) {
Parse.Cloud.run('hello', { test: 'test'}, {
success: function(success) {
console.log(' Hello success.');
},
error: function(error) {
console.error(' hello failed.');
console.error("Got an error " + error.code + " : " + error.message);
}
});
});
Everything like parse commanded in docs
But when I save user it produces error:
I2015-08-14T06:33:16.709Z] hello failed.
I2015-08-14T06:33:16.711Z]Got an error 209 : invalid session token
How can it be? Am I doing something wrong?
[EDIT]
putting this at the beginning of afterSave trigger helped:
Parse.Cloud.useMasterKey();
I understand this is kind of root command, omitting all ACL restrictions. Can't see where I crossed such restrictions while running simple Hello World function example.
来源:https://stackoverflow.com/questions/32004227/cloudcode-user-aftersave-requires-usemasterkey-why