0

I have defined a function in Parse.com's Cloud Code. According to documentation the request.usr should be "The Parse.User that is making the request. This will not be set if there was no logged-in user.".

Im invoking my method from iOS and the user object is "empty", as in all attributes are undefined.

I guess Im missing how to set it when invoking the cloud code.

Here are my pieces:

1) cloud code

Parse.Cloud.define("userRatesMovie", function(request, response) {
  //Parameters: user, movieId, rating
  var user = request.user;
  var username = "nothing"
  var movieId = request.params.movieId;
  var rating = request.params.rating;

  var aux = "User: " + username + " Rated: " + movieId + " with a " + rating + " user " + user.username +":" +user.objectId;
  console.log(aux);

  //Fetch for previous rating for this user,movie pair
  response.success(aux);
});

For now Im just writing and returning a log line.

2) iOS code

    //Test code
PFUser *pfUser = [PFUser currentUser];
NSLog(@"User Id:%@ Username:%@",pfUser.objectId, pfUser.username);
[PFCloud callFunctionInBackground:@"userRatesMovie"
                   withParameters:@{
                                    @"movieId":@"12345",
                                    @"rating":@"3"}
                            block:^(NSString *someString, NSError *error) {
                                if (!error) {
                                    NSLog(@"userRatesMovie:%@",someString);
                                }
                            }];

I first check that I have a PFUser and then invoke my cloud code

3) Output

    User Id:32P3Hwk1Hv Username:1NpFRFVPFJT45znXosx8g8Ay2
    userRatesMovie:User: nothing Rated: 12345 with a 3 user undefined:undefined

As you can see user.username and user.objectId are undefined.

2
  • Do you have enable automatic user on? Commented Apr 28, 2015 at 22:57
  • @gonso how did u solve it? Commented Oct 25, 2015 at 13:38

1 Answer 1

2

The error wasn't sending the user, but the code that checked for it:

user.username

That is not a valid Cloud Code syntaxis. The correct code should look like this:

user.get("username")

Then it all worked fine....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.