Skip to content

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

Closed

Description

@sraveh

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

Activity

  1. gfosco commented on Feb 2, 2016

    @gfosco
    Contributor

    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/

  2. sraveh commented on Feb 3, 2016

    @sraveh
    Author

    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

  3. gfosco commented on Feb 3, 2016

    @gfosco
    Contributor

    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!

  4. xwizi commented on Feb 3, 2016

    @xwizi

    @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.

  5. gfosco commented on Feb 3, 2016

    @gfosco
    Contributor

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

  6. xwizi commented on Feb 3, 2016

    @xwizi

    @gfosco : Am i right in saying that all queries need to use the user session token? Do the acl's work: can you confirm?

  7. sraveh commented on Feb 3, 2016

    @sraveh
    Author

    This fixed my issue, request.user is now available

  8. evblurbs commented on Feb 5, 2016

    @evblurbs

    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;
  9. drew-gross commented on Feb 11, 2016

    @drew-gross
    Contributor

    Looks like this is fixed.

  10. added a commit that references this issue on Feb 22, 2017
  11. mtrezza commented on Jul 18, 2021

    @mtrezza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions