0

I am currently trying to override sessionAuthenticationSucceeded in the Ember.SimpleAuth.ApplicationRouteMixin class, so that I can transition into my routeAfterAuthentication with a model passed in.

Basically this.transitionTo(Configuration.routeAfterAuthentication, model);, but even after doing Ember.SimpleAuth.ApplicationRouteMixin.reopen() my override of the function is never called. So am I going about this all wrong? Can Mixins not be reopened in this fashion? Or should I be passing the model to the routeAfterAuthentication transition in a different fashion.

EDIT: Stupid reputation limits, was gonna answer this myself but apparently have to wait 8 hours, so here is that answer for now:

Well, not entirely sure if this is the correct way to do this, but it works. I was looking through this example: custom-server and I wound up doing this to accomplish what I wanted.

var applicationRoute = container.lookup('route:application');
var session = container.lookup('ember-simple-auth-session:main');
var store = container.lookup('store:main');

session.on('sessionAuthenticationSucceeded', function() {
    var user = store.find('user', session.get('user_id'));
    container.lookup('controller:application').set('content', user)
    applicationRoute.transitionTo('profile.resume', user);
});
HunterS
  • 1
  • 3

2 Answers2

1

The easiest solution would be to simply define the sessionAuthenticationSucceeded on the application route instead of reopening the mixins:

/// routes/application.js
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {
  actions: {
    sessionAuthenticationSucceeded: function() {
      …
    }
  }
})
Buck Doyle
  • 6,333
  • 1
  • 22
  • 35
marcoow
  • 4,062
  • 1
  • 14
  • 21
  • I should have came back and edited this, but I found a solution based on one of your examples, which I shall add as an answer below. – HunterS Jun 26 '14 at 15:23
  • Yeah, but that solution is meant to be used if you're not using the mixins. If you're using the mixins the solution below is unnecessarily complex. – marcoow Jun 26 '14 at 15:30
  • That makes sense, I did notice that with my current solution the transitionTo first starts within the RouteMixin and then is aborted and redone within the session.on. Thanks for the tip! – HunterS Jun 27 '14 at 00:26
0

Well, not entirely sure if this is the correct way to do this, but it works. I was looking through this example: custom-server and I wound up doing this to accomplish what I wanted.

var applicationRoute = container.lookup('route:application');
var session = container.lookup('ember-simple-auth-session:main');
var store = container.lookup('store:main');

    session.on('sessionAuthenticationSucceeded', function() {
        var user = store.find('user', session.get('user_id'));
        container.lookup('controller:application').set('content', user)
        applicationRoute.transitionTo('profile.resume', user);
    });
HunterS
  • 1
  • 3