我正在使用 ember-simple-auth 从快速服务器获取令牌。从 /api/account 请求帐户详细信息并存储在会话中。
当用户注销时,ember-data 记录被清除,account 和 accountId 被清除。当下一个用户登录时,没有为该用户进行 api 调用,只是收集了身份验证令牌。我怎样才能接到这个电话?这是我的设置:
Ember.Application.initializer({
name: 'authentication',
initialize: function(container, application) {
//customize the session so that it handles the additional authenticated account
Ember.SimpleAuth.Session.reopen({
init: function() {
this._super();
//initializer the accountId from data potentially already present in a
//session cookie (Ember.SimpleAuth.Session does this out of the box for authToken)
var accountId = (document.cookie.match(/accountId=([^;]+)/) || [])[1];
this.set('accountId', accountId);
},
setup: function(serverSession) {
this._super(serverSession);
console.log('+++' + serverSession.user_id);
this.set('accountId', serverSession.user_id);
},
destroy: function() {
this._super();
var accountId = this.get('accountId');
container.lookup('store:main').unloadAll('account');
this.set('account', undefined);
this.set('accountId', undefined);
},
accountIdChanged: function() {
//save accountId in a session cookie so it survives a page reload (Ember.SimpleAuth.Session
//does this out of the box for authToken)
document.cookie = 'accountId=' + this.get('accountId');
}.observes('accountId'),
account: function() {
var accountId = this.get('accountId');
console.log('---' + accountId);
if (!Ember.isEmpty(accountId)) {
this.set('account', container.lookup('store:main').find('account', accountId));
console.log('now');
}
}.property('accountId')
});
//set a custom session endpoint
Ember.SimpleAuth.setup(container, application, {
routeAfterLogin: 'main',
routeAfterLogout: 'login',
loginRoute: 'login',
serverTokenEndpoint: '/token',
autoRefreshToken: 'false'
});
}
});