0

最初にログインして、いくつかの小道具を に設定すると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}}未定義、

どうすればこれを解決できますか?

どうも

4

0 に答える 0