Node.js Can';t为未登录的用户访问视图中的customData-Express.js Stormpath

Node.js Can';t为未登录的用户访问视图中的customData-Express.js Stormpath,node.js,express,stormpath,Node.js,Express,Stormpath,遵循本教程: 我可以轻松访问和显示viewprofile.jade,登录用户的自定义数据,从profile.js使用 username: req.user.username, city: req.user.customData.city, 文件名:profile.jade h1 This is surname #{username} and #{city} 我想在视图中显示URL处未登录用户的数据: 我开始工作了-除了我不能访问任何自定义数据 文件名:server.js 我有这套 app

遵循本教程:

我可以轻松访问和显示viewprofile.jade,登录用户的自定义数据,从profile.js使用

username: req.user.username,
city: req.user.customData.city,
文件名:profile.jade

h1 This is surname #{username} and #{city}

我想在视图中显示URL处未登录用户的数据: 我开始工作了-除了我不能访问任何自定义数据

文件名:server.js 我有这套

app.use(stormpath.init(app, {
  expand: {
    customData: true

问题是: 文件名:user.jade

h1 This is surname #{username} and #{city}
用户名将显示,但城市没有显示任何内容

h1 This is surname #{username} and #{city}

哪里出错了?

如果您直接获取Stormpath应用程序对象并使用它进行API调用,那么实际上需要将
{expand:'customData'}
参数添加到每个API调用中

我知道您已经为express stormpath配置设置了它——这只适用于应用程序代表您进行的API调用(例如req.user)。我能看出这看起来有多混乱

因此,要实现这一点,只需更换:

    req.app.get('stormpathApplication').getAccounts({
        username: id
    }
与:


事情应该是这样的。快乐编码

谢谢,这是一个完美的解决方案。我知道我可以返回包含所有customData的JSON对象,但这是一个非常简单的解决方案。
    req.app.get('stormpathApplication').getAccounts({
        username: id,
        expand: 'customData'
    }