Parse-server: Parse.User.current not working? Do i use something else?

Created on 10 Jun 2016  路  4Comments  路  Source: parse-community/parse-server

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

Most helpful comment

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

All 4 comments

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

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lorki picture lorki  路  3Comments

ShawnBaek picture ShawnBaek  路  4Comments

omyen picture omyen  路  3Comments

dcdspace picture dcdspace  路  3Comments

shardul08 picture shardul08  路  3Comments