Search code examples
ember-cliember-simple-auth

Ember CLI Simple Auth RouteMixins not working


Session is working and no errors are being displayed, but none of the routeMixins are working... I've seem some similar issues and their solutions, but somehow they do not fix mine (or I misunderstood their implementation.) Here is my current Application router:

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

export default Ember.Route.extend
({
    ApplicationRouteMixin,
    model: function()
    {
        return Ember.Object.create
        ({
            genres: this.store.findAll('genre'),
            factTypes: this.store.findAll('factType'),
            categories: this.store.findAll('category')
        });
    },
    setupController: function(controller, models)
    {
        this._super(controller, models);
    }
});

I also tried the following without any success:

beforeModel: function(transition, queryParams)
{
    this._super(transition, queryParams);
},

and

model: function(transition, queryParams)
{
    this._super(transition, queryParams);
    return Ember.Object.create
    ({
        genres: this.store.findAll('genre'),
        factTypes: this.store.findAll('factType'),
        categories: this.store.findAll('category')
    });
}

Some of the routeMixins that I am using on my application:

User.edit

import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin);

Login route

import Ember from 'ember';
import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';

export default Ember.Route.extend
({
    UnauthenticatedRouteMixin,
    setupController: function(controller)
    {
        controller.set('errorMessage', null);
    }
});

Solution

  • Once again I missed the details... The answer for this specific problem is to move the RouteMixins to before the export default opening bracket as seen below:

    Application Route

    import Ember from 'ember';
    import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
    
    export default Ember.Route.extend
    (ApplicationRouteMixin, {
        model: function()
        {
            return Ember.Object.create
            ({
                genres: this.store.findAll('genre'),
                factTypes: this.store.findAll('factType'),
                categories: this.store.findAll('category')
            });
        }
    });
    

    Login Route

    import Ember from 'ember';
    import UnauthenticatedRouteMixin from 'simple-auth/mixins/unauthenticated-route-mixin';
    
    export default Ember.Route.extend
    (UnauthenticatedRouteMixin,{
        setupController: function(controller)
        {
            controller.set('errorMessage', null);
        }
    });
    

    I should have deleted the question, but you never know if someone else also makes the same mistake and have a hard time detecting it... You can see the docs here