dimanche 8 novembre 2015

Ember: ESA: sessionAuthenticated doesn't called

I want to perform some code when ember-simple-auth session get authenticated.

routes/application.js

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {
    currentUser: Ember.inject.service('current-user'),
    ajax: Ember.inject.service('ajax'),

    actions: {
        authSuccess: function() {
            var self = this;
            self.get('ajax').request({
                url: "http://ift.tt/20zaKEE",
                method: "GET"
            }, function(response) {
                Ember.$('#loginWindow').modal('hide');
                self.get('currentUser').setUser(response);
            }, function(xhr, status, error) {
                if (status === "Incorrect credentials") {
                    self.set('hasError', true);
                }
            });

        }
    },

    sessionAuthenticated: function() {
        console.log("auth success!");
    },

    sessionInvalidated: function() {
        console.log("401");
    }
});

autheticators/digest.js

import Base from 'ember-simple-auth/authenticators/base';
import Ember from 'ember';
import CryptoJS from 'npm:crypto-js';

export default Base.extend({

    restore: function(data) {
        if (data.email && data.password) {
            return new Ember.RSVP.Promise(function(resolve, reject) {
                resolve({email: data.email, password: data.password, digests: {}});
            });
        }
    },

    authenticate: function(email, password) {
        var self = this;
        return new Ember.RSVP.Promise(function(resolve, reject) {
            Ember.run(function() {
                resolve({email: email, password: password, digests: {}});
            });
        });
    },

    invalidate: function(data) {
        //
    }
});

restore() function successfully called on application start and resolve() in it called too. I expect "auth success!" string in console, but get nothing. Is this a bug or it's some mistake in my code? Thanks.




Aucun commentaire:

Enregistrer un commentaire