问题
I have a question regarding an invalid session token that I am getting in an afterSave method on a user object. I literally run the same query in the beforeSave and the afterSave in Parse cloud code and the one in the before save works while the one in the afterSave does not. I was wondering if there is something that I am not understanding in regards to how Parse works in that I am getting an invalid session token in the afterSave method but no problems in the beforeSave method.
Here is the query...
var AccessCode = Parse.Object.extend("AccessCode");
var query = new Parse.Query(AccessCode);
query.equalTo("code", accessCode);
query.notEqualTo("isUsed", true);
query.find({
success: function(results) {
//do some things
},
error: function(error) {
//display the error
}
})
回答1:
I solved this problem by changing the code a little bit...
Parse.Cloud.useMasterKey();
var query = new Parse.Query("AccessCode");
query.equalTo("code", accessCode);
query.notEqualTo("isUsed", true);
query.find({
success: function(results) {
//do some things
},
error: function(error) {
//display the error
}
})
All works fine an dandy now, but I am still unsure why it all didn't work in the first place.
回答2:
For some reason, afterSave on a Parse User object requires:
Parse.Cloud.useMasterKey();
to be able to work.
Not sure why, but other have reported the same issues. I struggled with this for a little while, everything worked after just adding master key stuff at the start of the afterSave.
来源:https://stackoverflow.com/questions/33003348/invalid-session-error-parse-aftersave-on-user-in-cloud-code