Search code examples
parse-cloud-codeparse-server

request.user not set in Cloud Code function


I'm calling a Cloud Code function from a JavaScript application with a logged-in user, like this:

if (Parse.User.current()) { // just to assert there is a logged-in user
  Parse.Cloud.run('foo').then(...);
}

In the Cloud Code function I want to access the current user (i.e. the user from whose context the function is called):

Parse.Cloud.define('foo', (req, res) => {
  var user = req.user;
  //...
}

Unfortunately, user is undefined. Is this code supposed to work, or is there an obvious mistake?

P.S.: Using parse-server 2.2.7 (based on parse-server-example) and parse-SDK-JS 1.8.3.


Solution

  • 1-> Make sure you update to the latest version of the Parse Server.

    sudo npm install parse-server@latest -g
    

    At the time of this writing, this should be 2.2.7.
    ref: https://github.com/ParsePlatform/parse-server/releases

    2-> Make sure the User has a valid session.
    @hramos: "request.user will only point to a _User object when the function is triggered by an authenticated user."

    ref: https://github.com/ParsePlatform/parse-server/issues/1619


    In other words...., logout and then log back in.