对于未login的用户,无法访问customData – Express.js Stormpath
以下教程:
A Simple Web App With Node.js, Express, Bootstrap & Stormpath
我可以轻松访问和显示在profile.jade ,customData为login用户,从profile.js与显示
username: req.user.username, city: req.user.customData.city,
文件名:profile.jade
h1 This is surname #{username} and #{city}
我想在一个视图中显示一个非login用户的数据,我的url为: http:// localhost:3000 / -jsmith ,但我无法访问任何customData。
FILENAME:server.js我有这个设置。
app.use(stormpath.init(app, { expand: { customData: true
和
app.get('/-:id', function(req, res, next) { console.log('the response will be sent by the next function ...'); var id = req.params.id; next(); }, function(req, res) { var id = req.params.id; req.app.get('stormpathApplication').getAccounts({ username: id }, (err, accounts) => { if (err) throw err; accounts.each((account, cb) => { console.log('Found matching account:', account); cb(); res.render('user', { email: account.email, city: account.customData.city, }); }); }); } );
问题:
文件名:user.jade
用户名显示,但没有为城市
h1 This is surname #{username} and #{city}
我哪里错了?
如果直接使用Stormpath Application对象并使用它进行API调用,则实际上需要为每个API调用添加{ expand: 'customData' }
参数。
我知道你已经为你的express-stormpathconfiguration设置了它 – 这只适用于应用程序为你的API调用(例如req.user)。 我可以看到这似乎令人困惑。
所以要做到这一点,只需更换:
req.app.get('stormpathApplication').getAccounts({ username: id }
附:
req.app.get('stormpathApplication').getAccounts({ username: id, expand: 'customData' }
而事情应该工作。 快乐的编码!
- 警告:意外的块“脚本”翡翠
- FIREBASE警告:用户callback抛出exception。 TypeError:req.next不是一个函数
- TypeError:对象函数(req,res,next){app.handle(req,res,next); }没有方法“configuration”
- Express:是否可以绕过静态文件的会话?
- 如何在Node.JS中分别接收req.body.model的所有对象而不是它的所有variables?
- 无法通过express / mongoose / angularjs从Mongodb访问数据
- Mongoose.js仅在定义/更改时更新单个属性
- 在express res.cookie中选项“path”是什么意思?
- 如何将expression式parameter passing给nodejsasynchronous调用