繁体   English   中英

Ember-Simple-Auth注销并在

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM