我从session.isAuthenticated中得到了不同的行为,取决于我如何访问它。这可能只是我真正问题的一个症状。
发生了什么:
session.isAuthenticated的模板不会更改显示状态(即继续操作,好像它是假的或未定义的)。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时,这些警告还能正常工作,所以我认为它们仍然没有问题。
templates/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>routes/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'));
}
}
});adapters/application.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
host: 'https://myprovider.herokuapp.com',
namespace: 'api/v2'
});authenticators/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'
}
}
}
};
};发布于 2016-02-12 11:15:11
您必须将会话服务注入支持要在其中使用的模板的所有控制器/组件中。在使用application模板中的会话时,必须在application控制器中注入会话服务。将其注入application 路由并不能使其在模板中可用。
https://stackoverflow.com/questions/35353067
复制相似问题