How to reset and post custom data to Stormpath

108 Views Asked by At

I get JSON data from my client and want to save it to Stormpaths custom data using node.js with express.js:

I've got my basic post route:

app.post('/post', stormpath.loginRequired, function(req, res){
var data = req.body;
res.locals.user.customData.test = data;
res.locals.user.customData.save();

});

I basically want to overwrite the given data in customData.test and than save it, but right now it's adding the given data to customData.test.

How do i fix that?

1

There are 1 best solutions below

0
On BEST ANSWER

It sounds like you want to put the data properties directly onto the custom data object? I'd suggest using an "extend" function that will copy the data properties onto the customData object.

For example using Underscore extend:

_.extend(req.locals.user.customData, data);

I also really like xtend