parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.95k stars 4.78k forks source link

Parse.User.current not working? Do i use something else? #2020

Closed farhan-syed closed 8 years ago

farhan-syed commented 8 years ago

here is what im doing, the app.post works for login, but when it goes to app.get, Parse.User.current is null

app.post('/login', function(req, res) {
  Parse.User.logIn(req.body.username, req.body.password, {
  success: function(user) {
    // Do stuff after successful login.
    console.log('user: ' + user);
    res.redirect('/home');
  },
  error: function(user, error) {
    // The login failed. Check error to see why.
    console.log('error login');
    res.redirect('/login');
  }
});

});

app.get('/home',function(req, res){

if (Parse.User.current()) {
      // No need to fetch the current user for querying Note objects.
  var currentUser = Parse.User.current();
  var sessionToken = currentUser.get('sessionToken');

  console.log(sessionToken);
    }
});
drew-gross commented 8 years ago

You'll need to switch to using an explicit session token in your queries if you make to make queries in cloud code as a specific user. See the migration guide: https://github.com/ParsePlatform/Parse-Server/wiki/Compatibility-with-Hosted-Parse#Cloud-Code

farhan-syed commented 8 years ago

Not trying to do cloud code, just logging in on a website

drew-gross commented 8 years ago

This repo is for issues in Parse Server, not for help building your app. That said, you can't use current user in a node environment. Imagine what would happen when one person hits the login endpoint, then then a second one hit the login endpoint, then the first one hit the home endpoint. Current user would still be set to the second user. This is why current user doesn't exist in node.

What you should do instead is store a session token on the client, and use that session token in your requests.

farhan-syed commented 8 years ago

is there some guide on this? i do have parse-express-cookie-sesion