Parse.User.current() in cloud code
Hi,
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.
Thanks, Simon
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/
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
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.
2.0.5 is out, let me know if this fixes things for you.
@gfosco : Am i right in saying that all queries need to use the user session token? Do the acl's work: can you confirm?
This fixed my issue, request.user is now available
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.
var Parse = require('parse/node').Parse;
Looks like this is fixed.
@byroncoetsee This is not the right place to ask because it is not related to the specific issue, which is also closed.
For help with Parse Server, here are some resources you can try:
- For code-level questions we recommend Stack Overflow using the parse-platform tag.
- For network and server questions we recommend ServerFault using the parse-server tag
- For questions that are not appropriate for the above mentioned sites we recommend our community forum.