2

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'] でアクセスしようとすると、そこにありません。アカウントと req.user は異なる必要があります。ユーザーを保存するにはどうすればよいですか?

4

2 に答える 2

0

rdegges が提供する解決策は完全に正しいわけではありません。

への呼び出しnext()は、customData の保存が完了した直後ではなく、終了後にのみ呼び出す必要があるため、 のコールバックである必要がありますdata.save()

また、postRegistrationHandlerパラメータが から に変更されたようaccount, req, res, nextです。

現在有効なソリューションは次のとおりです。

postRegistrationHandler: function(account, req, res, next) {
    account.getCustomData(function(err, data) {
        if (err)
            return next(err);

        data.mongo_id = '54aabc1c79f3e058eedcd2a7';
        data.save(next);
    });
},
于 2015-07-16T08:40:36.277 に答える