Skip to content

Fetch user object from session token #3398

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

Closed
manishsangwan opened this issue Jan 19, 2017 · 10 comments
Closed

Fetch user object from session token #3398

manishsangwan opened this issue Jan 19, 2017 · 10 comments

Comments

@manishsangwan
Copy link

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.

@nuno
Copy link

nuno commented Jan 27, 2017

+1

@lzaiats
Copy link

lzaiats commented Feb 8, 2017

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();
  });
});

@hramos hramos closed this as completed Feb 10, 2017
@akshaychauhan7737
Copy link

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

@lzaiats
Copy link

lzaiats commented Nov 28, 2017

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 ;)

@akshaychauhan7737
Copy link

Thank You So much it Worked :)

@flovilmart
Copy link
Contributor

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

@lzaiats
Copy link

lzaiats commented Nov 28, 2017

@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

@akshaychauhan7737
Copy link

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

@flovilmart
Copy link
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 :)

@Jauny
Copy link

Jauny commented Oct 16, 2018

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants