我從session.isAuthenticated
獲取不同的行爲,具體取決於我如何訪問它。這可能只是我真正的問題的症狀。使用ember-simple-auth和torii自定義身份驗證器進行身份驗證
會發生什麼:在按鈕
- 點擊標誌
- 窗口彈出,提示登錄
- 登錄,彈出消失
- 模板依賴
session.isAuthenticated
不改變顯示狀態(即繼續 ,就好像它是假的或未定義的那樣) - 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'
}
}
}
};
};