恢复后Ember简单auth缺少道具

时间:2015-07-09 04:55:46

标签: ember.js ember-simple-auth ember-addon

当我第一次登录并将一些道具设置为this.get('session')时,一切正常。代码如下:

  actions: {
// display an error when authentication fails
authenticate: function() {
  var _this = this;
  var credentials = this.getProperties('identification', 'password');
  this.get('session').authenticate('authenticator:custom', credentials).then(
  function() {
    var username = _this.get('session.secure.data.name');
    //look here, I set a username props to session object
    _this.get('session').set('username', username);
    //debugger;
  }, function(message) {
    // but the reject callback works fine, the message is the right one
    _this.set('errorMessage', message.msg);
    _this.set('identification', '');
    _this.set('password', '');
  });
 }
}

和下面的hbs

{{#if session.isAuthenticated}}
  Hi,{{session.username}}
{{else}}
{{#link-to 'login'}} Login {{/link-to}}
  or
{{#link-to 'signup'}} Signup {{/link-to}}
{{/if}}

现在一切正常,但刷新页面后

{{session.username}}未定义,

我该如何解决这个问题?

THX

0 个答案:

没有答案