2016-02-12 55 views
0

我從session.isAuthenticated獲取不同的行爲,具體取決於我如何訪問它。這可能只是我真正的問題的症狀。使用ember-simple-auth和torii自定義身份驗證器進行身份驗證

會發生什麼:在按鈕

  1. 點擊標誌
  2. 窗口彈出,提示登錄
  3. 登錄,彈出消失
  4. 模板依賴 session.isAuthenticated不改變顯示狀態(即繼續 ,就好像它是假的或未定義的那樣)
  5. if if console.log this.get('session.isAuthenticated')我得到true

當這只是鳥居一切工作,所以我莫名其妙地增加燼,簡單認證方法時弄亂了。

我得到了幾個"DEPRECATION: Using the injected 'container' is deprecated. Please use the 'getOwner' helper instead to access the owner of this object警告,但當它只是torii它在這些警告中正常工作,所以我認爲他們仍然不是問題。

模板/ application.hbs

<header> 
    <nav class="nav-main"> 
    {{#if session.isAuthenticated}} 
     <button {{action 'invalidateSession'}}>Sign out</button> 
    {{else}} 
     <button {{action 'authenticate'}}>Sign in</button> 
    {{/if}} 

    Auth: {{session.isAuthenticated}}<br> 
    <button {{action 'icanhaz'}}>test?</button> 
    </nav> 
</header> 

路由/的application.js

import Ember from 'ember'; 
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; 

export default Ember.Route.extend(ApplicationRouteMixin, { 
    session: Ember.inject.service('session'), 
    actions: { 
    authenticate() { 
     this.get('session').authenticate('authenticator:torii', 'myprovider'); 
    }, 
    invalidateSession() { 
     this.get('session').invalidate(); 
    }, 
    icanhaz() { 
     console.log(this.get('session.isAuthenticated')); 
    } 
    } 
}); 

適配器/的application.js

import DS from 'ember-data'; 

export default DS.JSONAPIAdapter.extend({ 
    host: 'https://myprovider.herokuapp.com', 
    namespace: 'api/v2' 
}); 

鑑定人/ torii.js

import Ember from 'ember'; 
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii'; 

export default ToriiAuthenticator.extend({ 
    torii: Ember.inject.service(), 
}) 

environment.js

module.exports = function(environment) { 
    var ENV = { 
    modulePrefix: 'my-app-prefix', 
    environment: environment, 
    baseURL: '/', 
    locationType: 'auto', 
    }, 
    contentSecurityPolicy: { 
     'connect-src': "'self' myprovider.herokuapp.com", 
    }, 
    torii: { 
     providers: { 
     'myprovider': { 
      apiKey: '6T7hlTUqfYMgcxkXPAOeNzVmC5L26bTYe9A8D5fc', 
      scope: 'read write', 
      redirectUri: 'http://localhost:4200' 
     } 
     } 
    } 
    }; 
}; 

回答

0

你必須注入會話服務的成所有控制器/組件背面要在使用會議模板。當您在application模板中使用會話時,您必須在application控制器中注入會話服務。將其注入application路線不會使其在模板中可用。

相關問題