2

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.

dr_barto
  • 5,723
  • 3
  • 26
  • 47

1 Answers1

1

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.
Community
  • 1
  • 1
efe.osazee
  • 26
  • 1
  • 2
  • As stated in my question, I'm already using parse-server 2.2.7. I also tried multiple logouts/logins without success. Nevertheless, one day later and after changing lots of code (but nothing that should influence that issue) I do get the current user in the CC request object. So thanks anyway :) – dr_barto May 01 '16 at 15:12
  • @dr_barto I'm facing the same issue, but the point is that I'm getting the user back, sometimes, if I reset the server, or not, etc etc... it's happening random. – Rafael Ruiz Muñoz Jul 24 '16 at 11:23
  • I know this issue is checked off, but is it possible this is only happening on the simulator? – mogile_oli Nov 30 '16 at 20:56