2015-12-14 235 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 }}