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 行如何打印出带有 mongo_id 属性的 customData。当我稍后尝试使用 req.user.customData['mongo_id'] 访问它时,它不存在。Account 和 req.user 必须不同。如何保存用户?