Stormpath documentation ничего не говорит об изменении атрибутов пользователя в PostRegistrationHandler, и мне нужно это сделать.Express.js Stormpath PostRegistrationHandler
После создания пользователя, я хочу дать ему случайную строку как свойство. Эта случайная строка будет ключом к моей отдельной базе данных Mongo. В моем app.js, у меня есть:
app.use(stormpath.init(app, {
postRegistrationHandler: function(account, res, next) {
// theoretically, this will give a user object a new property, 'mongo_id'
// which will be used to retrieve user info out of MONGOOOO
account.customData["mongo_id"] = "54aabc1c79f3e058eedcd2a7"; // <- this is the thing I'm trying to add
console.log("RESPNSE:\n"+res);
account.save(); // I know I'm using 'account', instead of user, but the documentation uses account. I don't know how to do this any other way
next();
console.log('User:\n', account, '\njust registered!');
},
apiKeyId: '~/.stormpath.apiKey.properties',
//apiKeySecret: 'xxx',
application: ~removed~,
secretKey: ~removed~,
redirectUrl: '/dashboard',
enableAutoLogin: true
}));
Я не знаю, как мой console.log линию НЕ распечатать CustomData с атрибутом mongo_id. Когда я попытаюсь получить к нему доступ позже с req.user.customData ['mongo_id'], его там нет. Учетная запись и req.user должны быть разными. Как я могу сохранить пользователя?
Вопрос: Вы используете опцию «expandCustomData» для библиотеки? – robertjd
Я не использую expandCustomData – Mike
Можете ли вы попробовать добавить эту опцию? Я подозреваю, что это может потребоваться для работы с пользовательскими данными в обработчике post registration – robertjd