2016-10-15 67 views
1

我有一個簡單的StormPath/Express應用程序,並且在用戶註冊後,我想將country的默認值設置爲「World」(customData)。稍後用戶可以在其個人資料頁面上將其更改爲任何國家/地區。註冊後設置默認值,StormPath

我將如何使用preRegistrationHandler來完成此操作(如果這是最好的方式)。謝謝。

app.use(stormpath.init(app, { 
    preRegistrationHandler: function (formData, req, res, next) { 
    console.log('Got registration request', formData); 
    next(); 
} 

})); 

回答

0

您要使用的postRegistrationHandler登記後已完成運行代碼=)

例如:

app.use(stormpath.init(app, { 
    postRegistrationHandler: (account, req, res, next) => { 
    account.getCustomData((err, data) => { 
     if (err) return next(err); 
     data.country = 'World'; 
     data.save((err) => { 
     if (err) return next(err); 
     next(); 
     }); 
    }); 
    }); 
});