Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to update an User with useMasterKey #4450

Closed
JulienRcs opened this issue Dec 24, 2017 · 4 comments
Closed

Unable to update an User with useMasterKey #4450

JulienRcs opened this issue Dec 24, 2017 · 4 comments

Comments

@JulienRcs
Copy link

Issue Description

I'm trying to update an User when another user click on my Xamarin button.
Then, I used Cloud Code to perform this but it doesnt work

Steps to reproduce

Here is my complete JS code :

Parse.Cloud.beforeSave("Archive", function(request, response) {
  Parse.serverURL = 'https://pg-app-0brffxkawi8lqvf2eyc2isqrs66zsu.scalabl.cloud/1/';
  var status = request.object.get("status");
  if (status == "validated") {
    var event = request.object.get("event");
    event.fetch({
      success: function(myEvent) {
        var coinsEvent = myEvent.get("coins");
        var user = request.object.get("user");
         user.fetch({
          success: function(myUser, coinsEvent, user) {
            var email = myUser.get("email");
            var coinsUser = myUser.get("coins");
            myUser.set("coins", coinsUser + coinsEvent);
            return myUser.save(null, {useMasterKey:true});
          }
        });
      }
    });
  }
  response.success();
});

Expected Results

return myUser.save(null, {useMasterKey:true});

Should work

Actual Outcome

I actually have that error :

Dec 24, 2017, 12:27 GMT+1 - ERRORError generating response for [PUT] /1/classes/_User/1GPcqmn6Hd
"Cannot modify user 1GPcqmn6Hd."

{
"coins": 250
}

Environment Setup

  • Server
    • parse-server version (Be specific! Don't say 'latest'.) : v2.3.3
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Sashido
@coryshaw
Copy link

coryshaw commented Jan 3, 2018

Your code looks good. The only thing I can think of is that you are not initializing parse with your master key.

Parse.initialize(process.env.PARSE_APP_ID, '', process.env.PARSE_MASTER_KEY);

Or perhaps "coins" is not a number field?

@tolgaatam
Copy link

did you really need to put your server url in the cloud code? all information is passed to the cloud functions automatically

@tolgaatam
Copy link

it seems like your problem occurs where your response.success() is called before any of your async functions calls are submitted. you can call response.success() at two spots, first in the else statement of status == "validated" and secondly in the success callback of your myUser.save rather than returning that promise.

@JulienRcs
Copy link
Author

Yes, the problem was the "response.success()", thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants