samedi 22 avril 2017

ember: TypeError: Cannot read property 'set' of undefined

I am trying set a value into userSessionStorage, when i am accessing it from the authenticate() function it seems to work correctly.

However, it is not working in the .then() promise.

app/controllers/show.js

import Ember from 'ember';
import { storageFor } from 'ember-local-storage';

export default Ember.Controller.extend({
  session: Ember.inject.service('session'),

  userSessionStorage: storageFor('user'),

  authenticator: 'authenticator:custom',

  actions: {
    authenticate: function() {
      var credentials = this.getProperties('identification', 'password');
      // ok
      this.set('userSessionStorage.username', credentials.identification);

      this.get('session').authenticate('authenticator:custom', credentials)
        .then(function(){

          // error: TypeError: Cannot read property 'set' of undefined
          this.set('userSessionStorage.username', credentials.identification);

        })
        .catch((message) => {
          console.log("message: " + message);

          this.controller.set('loginFailed', true);
        });
    }
  }
});




Aucun commentaire:

Enregistrer un commentaire