在使用 Express-Stormpath 模块通过 node/express 将用户注册到 Stormpath 后,我遇到了一个奇怪的错误(至少在我看来)。
刚注册后,我似乎无法在第一个用户会话的各种路线中访问 customData。在注册时,我正在为发票创建和排列
app.use(stormpath.init(app, {
...,
expandCustomData: true,
postRegistrationHandler: function(account, req, res, next) {
account.customData.invoices = [];
account.save();
next();
}
}));
但是当我在我的索引路径中访问它们时,我得到了这个错误
router.get('/', stormpath.loginRequired, function(req, res){
console.log(req.user.customData.invoices ); // undefined
res.render('index', {
title: 'Index'
});
});
如果我杀死我的本地并重新启动它,我会怎么做
console.log(req.user.customData.invoices ); // []
这就是我想要的。
谁能阐明我在这里做错了什么?
提前谢谢。