Skip to content
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

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

Closed
farhan-syed opened this issue Jun 9, 2016 · 4 comments
Closed

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

farhan-syed opened this issue Jun 9, 2016 · 4 comments

Comments

@farhan-syed
Copy link

farhan-syed commented Jun 9, 2016

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
Copy link
Contributor

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
Copy link
Author

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

@drew-gross
Copy link
Contributor

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
Copy link
Author

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

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

2 participants