2015-12-14 192 views
0

当我登录到我的流星网站用电子邮件地址和密码,{{>loginButtons}}显示我的用户名:流星:登录用户名不符合社会登录显示

Username is showing

<li id="login-dropdown-list" class="dropdown"> 
    <a class="dropdown-toggle" data-toggle="dropdown"> 
    "Yngve Høiseth" 
    <b class="caret"></b> 
    </a> 
    <div class="dropdown-menu"> 
    <button class="btn btn-block btn-primary" id="login-buttons-logout"> 
     Logg ut 
    </button> 
    </div> 
</li> 

然而,当我登录与Twitter或Facebook,无名称表示:

Username not showing

<li id="login-dropdown-list" class="dropdown"> 
    <a class="dropdown-toggle" data-toggle="dropdown"> 
    <b class="caret"></b> 
    </a> 
    <div class="dropdown-menu"> 
    <button class="btn btn-block btn-primary" id="login-buttons-logout"> 
     Logg ut 
    </button> 
    </div> 
</li> 

这与accounts-uiian:accounts-ui-bootstrap-3都有发生。

我没有做任何事情 - 只包括模板。我试过在导航栏外放{{>loginButtons}},我尝试手动刷新页面,无济于事。

+0

什么是'Meteor.user()'在客户端上对象的内容?特别是当你通过Twitter或Facebook登录时,有一个“profile.name”字段? – Curtis

+0

不,没有'profile.name'。只有对象{_id:“MhEZ2G7rKSa2rGrBR”}'。 –

+0

'{{> loginButtons}}'使用'Meteor.user().profile.name'值填充下拉列表。您可能不会将您的配置文件发布到客户端。 – Curtis

回答

0

发生这种情况的原因是,当您使用email-password和其他第三方登录服务时,users架构有点不同。为了显示记录的用户名,您需要创建一个全球帮助器users,并在您的blaze中调用它。

Meteor.users.helpers({ 
fullName: function() { 
    if (_.has(this.services, 'facebook')) { 
     return this.services.facebook.name; 
    } 

    if (_.has(this.services, 'google')) { 
     return this.services.google.name; 
    } 

    return null; 
} 
}); 

上面的代码演示了如何定义全局帮助器。检查你的users数据库模式并相应地获取名称。 那么你就需要在这样的观点打电话:

{{ currentUser.fullName }}