niftygrifty
niftygrifty

Reputation: 3652

Ember: Add mixin to every route except one

Using Ember-Simple-Auth in an Ember-Cli app, I'm trying to require authentication on pretty much every route in my application. I didn't want to use the AuthenticatedRouteMixin on every route, because I don't want to have to define every route. So I added the mixin to ApplicationRoute.

However, this causes an infinite loop, because obviously the login route extends from the same ApplicationRoute and therefore now protected.

How do I include this mixin in every route except LoginRoute?

Upvotes: 4

Views: 337

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

I doubt you need it at every route, more than likely you just need it as a gate to authenticated resources.

App.Router.map(function(){
  this.route('login'); // doesn't need it
  this.resource('a', function(){ <-- need it here
    this.resource('edit');       <-- this is protected by the parent route
  });
  this.resource('b', function(){ <-- and here
    this.resource('edit');       <-- this is protected by the parent route
  });
});

or you can take it one level deeper and just create a route that wraps everything:

App.Router.map(function(){
  this.route('login'); // doesn't need it
  this.resource('authenticated', function(){ <-- put it here
    this.resource('a', function(){ <-- this is protected by the parent route
      this.resource('edit');       <-- this is protected by the grandparent route
    });
    this.resource('b', function(){ <-- this is protected by the parent route
      this.resource('edit');       <-- this is protected by the grandparent route
    });
  });
});

Upvotes: 2

Related Questions