1

Folks,

I've been trying to get ESA to redirect to specific pages after login and logout events without success.

I'm trying to do this by overriding the "sessionAuthenticated" method, but have also tried setting the "routeAfterConfiguration" setting with no luck.

At the moment, login sends me to "/", and logout sends the app to "/undefined".

I'm using simple-auth-token as a JWT authenticator strategy.

The code for my application route looks like this...

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

export default Ember.Route.extend(ApplicationRouteMixin,{
    actions: {
      sessionAuthenticated: function() {
         console.log('sessionAuthenticated: authentications ok');
         window.location.replace('/profile');
     },
   },
});

My login.js is as follows:

import Ember from 'ember';
const {service} = Ember.inject;

export default Ember.Route.extend({
  session: service('session'),
  errorMessage: null,
  model: function(){
    return Ember.Object.create({
           identification:'', 
           password: '',      
           errorMessage: this.get('errorMessage')
    });
  },

  setupController: function(controller, model) {
    controller.set('credentials',model);
  },

  actions: {
    authenticate: function(credentials) {
      console.log(credentials);
      this.get('session').authenticate('simple-auth-authenticator:jwt', credentials)
    .catch((reason) => {
      console.log('Login Error');
      credentials.set('errorMessage', reason);
    });
  },
},

});

Does anyone have any idea what I might be doing wrong here?

Cheers,

Andy

Andy Davison
  • 541
  • 4
  • 13
  • Can you post any additional code related to simple auth? Your login action, any custom authenticator (or let us know which built-in one you're using), and simple-auth related ENV configuration. Also you should use `this.transitionTo('profile');` instead of using `window.location.replace` – Tom Netzband Dec 02 '15 at 00:02
  • Thanks Tom. More detail editted in above... – Andy Davison Dec 02 '15 at 08:52

1 Answers1

3

OK. Found the problem. These are not actions - they're methods. So I just had to promote the methods out of the actions object and it's all come good.

So the correct routes/application.js looks like this:

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

export default Ember.Route.extend(ApplicationRouteMixin,{
  sessionAuthenticated: function() {
     console.log('sessionAuthenticated: authentications ok');
     window.location.replace('/profile');
  },
});
Andy Davison
  • 541
  • 4
  • 13