Skip to content

server-side login (replacing parse-express-cookie-session) #497

@mchun

Description

@mchun

My app was relying on 'parse-express-cookie-session' offered by Parse to do server-side login, i.e.:

  app.post('/login', function(req, res) {
    Parse.User.logIn(req.body.username, req.body.password).then(function(user) {
      res.redirect('/');
    }, function(error) {
      res.render('login', { flash: error.message });
    });
  });

  app.post('/logout', function(req, res) {
    Parse.User.logOut();
    res.redirect('/');
  });

I used Parse.User.Current() to check if the user is logged in on server-side.

Now, I replaced the 'parse-express-cookie-session' by 'express-session'. And do the login/logout in this way:

  app.post('/login', function(req, res) {
    Parse.User.logIn(req.body.username, req.body.password).then(function(user) {
      req.session.user=user;
      res.redirect('/');
    }, function(error) {
      res.render('login', { flash: error.message });
    });
  });

  app.post('/logout', function(req, res) {
    req.session.user = null;
    res.redirect('/');
  });

I then see if the user is logged in by checking req.session.user = null . But I cannot access it inside cloudcode.
Perhaps this is not a right way to do(?) as it is recommended to use req.user, but I have no idea how to make it work, req.user is always null. Any help from you guys?
It would be great to even have a small sample app offered by Parse showing simple server-side login like Anyimg as there should be similar cases around like me.

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