Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse.User.current() in cloud code #188

Closed
sraveh opened this issue Feb 2, 2016 · 10 comments
Closed

Parse.User.current() in cloud code #188

sraveh opened this issue Feb 2, 2016 · 10 comments

Comments

@sraveh
Copy link

sraveh commented Feb 2, 2016

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

@gfosco
Copy link
Contributor

gfosco commented 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
Copy link
Author

sraveh commented 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
Copy link
Contributor

gfosco commented 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
Copy link

xwizi commented 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
Copy link
Contributor

gfosco commented Feb 3, 2016

2.0.5 is out, let me know if this fixes things for you.

@xwizi
Copy link

xwizi commented 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
Copy link
Author

sraveh commented Feb 3, 2016

This fixed my issue, request.user is now available

@evblurbs
Copy link

evblurbs commented Feb 5, 2016

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;

@drew-gross
Copy link
Contributor

Looks like this is fixed.

@mtrezza

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants