2014-03-25 28 views
3

我使用的是一個自定義Facebook身份驗證器,與ember-simple-auth example中給出的非常相似。我注入的屬性accountIDaccessToken到這裏的會議:如何訪問ember-simple-auth中的會話屬性?

if (fbResponse.status === 'connected') { 
    console.log("AccountID: " + fbResponse.authResponse.userID); 
    Ember.run(function() { 
    resolve({ 
    accessToken: fbResponse.authResponse.accessToken, 
    accountID: fbResponse.authResponse.userID 
    }); 
}); 

如果我正確讀取docs,我應該能夠使用session.accountID訪問accountID任何控制器。但是,我能找到的唯一方法是通過session.store._lastData.accountID,這可能不是正確的做法。

更具體地說,在控制器,我有一個動作:

createRental: function() { 
     var session = this.get('session'); 
     console.log(session.accountID); // undefined 
     console.log(session.store._lastData.accountID); // '123456' 

有誰使用經驗燼,簡單AUTH知道是什麼問題?謝謝!

回答

6

您需要使用get

this.get('session.accountID') 

var session = this.get('session'); 
session.get('accountID') 
+0

怎麼樣的模式?我想訪問我已附加到受保護資源的計算屬性中的會話的用戶對象。 –

+0

會話在模型中不可用。你可以用Ember的依賴注入API手動注入它(http://emberjs.com/guides/understanding-ember/dependency-injection-and-service-lookup/#toc_dependency-injection-with-code-register-inject-code )雖然在自定義初始化器中。 – marcoow

+0

使用Ember Inspector提供的'$ E'對象在控制檯中不起作用。 '例如,$ E.get('session.isAuthenticated')'起作用,但我無法使用此答案中的方法在'$ E.session.store._lastData.secure'內找到任何內容。使用模板的結果類似; '... _ lastData.secure.foo'被定義,但不是'session.foo'。 –