Stormpath Express: save user data

I start the express server with express-stormpath for auth and save the same user data about the user.

How can I send data to the server and save it in an assault path? Currently, my post is as follows:

app.post('/post', stormpath.loginRequired, function(req, res) {
   var stundenplan_data = req.body;
   console.log(stundenplan_data);
   req.user.customData.stundenplan = stundenplan_data;
   req.user.customData.save();
});

I get the necessary data that I want to publish to console.log, but if I call the data in another receive request, the user data will be empty.

+4
source share
1 answer

I am the author of the library express-stormpath, I would do this:

Stormpath , , customData :

app.use(stormpath.init(app, {
  ...,
  expandCustomData: true,  // this will help you out
}));

, :

app.post('/post', stormpath.loginRequired, function(req, res, next) {
  var studentPlan = req.body;
  console.log(studentPlan);
  req.user.customData.studentPlan = studentPlan;
  req.user.customData.save(function(err) {
    if (err) {
      next(err);  // this will throw an error if something breaks when you try to save your changes
    } else {
      res.send('success!');
    }
  });
});

, , , customData. Stormpath "" customData, , , .

, =)

+4

All Articles