You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my cloud code I'm using: var user = Parse.User.current(); this used to work correctly when running on Parse.com. now that I run it on my own server I get null back.
In hosted Parse each request loaded a whole instance of Cloud Code with no shared state, so Parse.User.current() made sense. In Node directly, like via webhooks or parse-server, the server stays running, so Parse.User.current() would be unstable. It is disabled in parse/node and the documented way of using users is to get the user from the request object, and pass session tokens directly to methods.
Thanks for the answer, I"m currently using parse": "~1.6.13" on the client and parse-server 2.0.4 for the server side. I'm getting TypeError: Cannot read property 'getSessionToken' of undefined when trying to use your example. It seems that req.user does not return a valid user. do I need to pass it when invoking the cloud code from the client? currently my client code looks like this: Parse.Cloud.run("funcation name", parameters)
Ah. It was landed in #172 but has not been released as a new version... There are 2 failing tests in master that I'm trying to clean up before tagging 2.0.5. You can make a similar change or just wait a bit longer. Thanks for your patience and understanding!
@gfosco: I have been following this issue - all my cloud functions look for the session user in the request - they also look for install id. It seems none of this works. Looking above it looks like I can get a session token and use that. However I was following #172 which seems to fix the issue that the user was not passed to cloud fn's - is this fix now released? Appreciate your efforts.
I'm getting the session token from the request.user object, but when I try to query for it, I get an unauthorized error. Do I need to initialize the Parse object again in the cloud code?
EDIT: Doh! Realized my error right after posting this question. I had forgot to require parse/node - was thrown off because the Parse object was still available.
Activity
gfosco commentedon Feb 2, 2016
In hosted Parse each request loaded a whole instance of Cloud Code with no shared state, so Parse.User.current() made sense. In Node directly, like via webhooks or parse-server, the server stays running, so Parse.User.current() would be unstable. It is disabled in parse/node and the documented way of using users is to get the user from the request object, and pass session tokens directly to methods.
See the Switching from Cloud Code to Node.js section here: http://blog.parse.com/learn/using-node-js-with-parse/
sraveh commentedon Feb 3, 2016
Thanks for the answer, I"m currently using parse": "~1.6.13" on the client and parse-server 2.0.4 for the server side. I'm getting TypeError: Cannot read property 'getSessionToken' of undefined when trying to use your example. It seems that req.user does not return a valid user. do I need to pass it when invoking the cloud code from the client? currently my client code looks like this: Parse.Cloud.run("funcation name", parameters)
Thanks,
Simon
gfosco commentedon Feb 3, 2016
Ah. It was landed in #172 but has not been released as a new version... There are 2 failing tests in master that I'm trying to clean up before tagging 2.0.5. You can make a similar change or just wait a bit longer. Thanks for your patience and understanding!
xwizi commentedon Feb 3, 2016
@gfosco: I have been following this issue - all my cloud functions look for the session user in the request - they also look for install id. It seems none of this works. Looking above it looks like I can get a session token and use that. However I was following #172 which seems to fix the issue that the user was not passed to cloud fn's - is this fix now released? Appreciate your efforts.
gfosco commentedon Feb 3, 2016
2.0.5 is out, let me know if this fixes things for you.
xwizi commentedon Feb 3, 2016
@gfosco : Am i right in saying that all queries need to use the user session token? Do the acl's work: can you confirm?
sraveh commentedon Feb 3, 2016
This fixed my issue, request.user is now available
evblurbs commentedon Feb 5, 2016
I'm getting the session token from the
request.userobject, but when I try to query for it, I get an unauthorized error. Do I need to initialize the Parse object again in the cloud code?EDIT: Doh! Realized my error right after posting this question. I had forgot to require
parse/node- was thrown off because theParseobject was still available.drew-gross commentedon Feb 11, 2016
Looks like this is fixed.
Merge pull request parse-community#188 from talkaboutdesign/master
mtrezza commentedon Jul 18, 2021