parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

User objects not exploded in cloud function params

Open codebreach opened this issue 10 years ago • 7 comments

Environment Setup

localhost node 3.6 mongo 3.0

Steps to reproduce

Parse.User.extend({
  method: function() { return 'hello world'; }
});
Parse.Cloud.define('customFunction', function(request, response) {
  response.success(request.user.method());
}); 

When called with a valid session token, customFunction will return hello world on Parse Cloud Code customFunction will throw TypeError: request.user.method is not a function on parse-server

codebreach avatar Apr 22 '16 19:04 codebreach

Perhaps you need to init a User before calling request.user.method()?

aaronbannin avatar Apr 25 '16 21:04 aaronbannin

We noticed this too but worked around it by either creating a new User with request.user.id or by querying the request.user. Not sure what the official stance is on this.

We extend as follows:

var User = Parse.Object.extend('_User', {
...
var query = new Parse.Query(User);

steven-supersolid avatar Apr 26 '16 09:04 steven-supersolid

I think the official stance should be to match the behavior on hosted Parse Cloud Code.

In that case handleCloudFunction can be updated to user: new Parse.Object('_User', req.auth.user)

I can make a PR if the owners can confirm the expected behavior

codebreach avatar Apr 26 '16 09:04 codebreach

I recommend making the PR anyway as it will have higher visibility and get things going

steven-supersolid avatar Apr 26 '16 10:04 steven-supersolid

This might we WAI I couldnt get this test to fail: https://github.com/drinklynk/parse-server/commit/136ee6def5f5fff84b1554a307943d54429072c7

codebreach avatar Apr 26 '16 11:04 codebreach

Yes, we are trying to match Parse.com behaviour in as many cases as we can. If you can submit a PR that gets us closer to Parse.com behaviour that would be much appreciated :)

drew-gross avatar Apr 26 '16 16:04 drew-gross

So I resolved this one and just wanted to make a note of it in case someone comes looking later. The issue was that there were TWO instances of Parse that were in my node_modules one under root and one under parse-server/node_modules

might be useful to have a warning when this is happening

codebreach avatar Jun 21 '16 21:06 codebreach