[英]Ember-Simple-Auth logout and in
我正在使用ember-simple-auth從快速服務器獲取令牌。 帳戶詳細信息從/ api / 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'
});
}
});
我在ember-simple-auth 0.11.1上遇到了同樣的問題,並最終將我的用戶(或帳戶)加載到設置功能中。 它似乎在那里很好用,並避免window.reload。
要使用您的代碼(未經測試):
setup: function(serverSession) {
this._super(serverSession);
console.log('+++' + serverSession.user_id);
accountId = serverSession.user_id;
if (!Ember.isEmpty(accountId)) {
this.set('account', container.lookup('store:main').find('account', accountId));
console.log('now');
}
}
我認為這
document.cookie = 'accountId=' + this.get('accountId');
是一個問題因為它會導致cookie被設置為
accountId=undefined
你需要...... 像這樣:
document.cookie = 'accountId=' + (this.get('accountId') || '');
要真正清除它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.