4

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?

niftygrifty
  • 3,452
  • 2
  • 28
  • 49

1 Answers1

2

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
    });
  });
});
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • 1
    Yup. This is just what I was looking for. I might add that I defined the an empty path, `{path: ''}`, on the authenticated resource so my url would look the same as before. Thanks! – niftygrifty Sep 09 '14 at 06:05