Skip to content

Fetch user object from session token #3398

Closed

Description

@manishsangwan

I want to create a middleware that fetches parse user object for given session token. So that i don't need to call cloud function every time.

Activity

  1. nuno commented on Jan 27, 2017

    @nuno

    +1

  2. lzaiats commented on Feb 8, 2017

    @lzaiats

    Parse.com used to have a request.user already setup for every request... On parse-server, it's not there anymore. I found this code snippet sometime ago that just solves the problem ;) I hope it helps you!

    app.use(function (req, res, next) {
      if(!req.session || !req.session.token) {
        return next();
      }
      
      Parse.Cloud.httpRequest({
        url: Parse.serverURL + '/users/me',
        headers: {
          'X-Parse-Application-Id': appid,
          'X-Parse-Session-Token': req.session.token
        }
      }).then(function (userData) {
        req.user = Parse.Object.fromJSON(userData.data);
        next();
      }, function(error) {
        next();
      });
    });
  3. akshaychauhan7737 commented on Nov 28, 2017

    @akshaychauhan7737

    it is not working for me error: httpRequest is not a funcion

  4. lzaiats commented on Nov 28, 2017

    @lzaiats

    I think newer versions of Parse.Cloud class does not have httpRequest anymore... You can use some other http lib to make the same request ;)

  5. akshaychauhan7737 commented on Nov 28, 2017

    @akshaychauhan7737

    Thank You So much it Worked :)

  6. flovilmart commented on Nov 28, 2017

    @flovilmart
    Contributor

    Parse.Cloud.httpRequest is available in parse-server, where did you read it wasn’t?

  7. lzaiats commented on Nov 28, 2017

    @lzaiats

    @flovilmart I am very sorry if I spread wrong info, but the new JS API docs does not contains any reference to Parse.Cloud.httpRequest...

    The JS SDK API docs used to have this info, and I always used it as my reference.

    After doing a more deep search I found that this info (Parse.Cloud.httpRequest) is now on http://docs.parseplatform.org/cloudcode/guide/#networking and I didn't knew that... My fault!

    LZ

  8. akshaychauhan7737 commented on Nov 28, 2017

    @akshaychauhan7737

    then why it dosn't worked for me when i tried.... I was using it on nodejs.

  9. flovilmart commented on Nov 28, 2017

    @flovilmart
    Contributor

    I need to add it back but it’s only available when running in CloudCode. Actually, all cloud code methods are missing from the docs now, I need to add them back :)

  10. Jauny commented on Oct 16, 2018

    @Jauny

    Does anybody know why I'm getting unauthorised when trying to hit /users/me on my server? I assume I have to have additional headers with the correct keys, but which ones? I can't find any docs on this.

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