1
votes

Is there any way to specify defaults for all generated Routes in Ember? For example, I need every route to check to see if the user is logged in before doing anything. Yes, I could make an authentication route, then extend every route from it, but ew. Then I've got all these empty routes everywhere just because I need to extend something else other than the default.

Is there any other way to do something like this? Preferably something that doesn't require me to create a Route for every single view in the application. Thoughts?

EDIT

To clarify a bit further about what I don't want, this is one of my route files:

import AuthenticatedRoute from '../routes/authenticated';
export default AuthenticatedRoute.extend();
1

1 Answers

0
votes

You can create a parent resource that is the authenticated route, and then put all of your routes that should be authenticated beneath it. You can't get to the child routes unless you get past the auth route. Honestly, even with your current structure, all of the child routes beneath an AuthenticatedRoute would be considered authenticated since they had to pass through that route to get there. (I prefer the explicit auth route in the router though)

App.Router.map(function() {
  this.resource('auth', {path:''}, function(){
    this.resource('foo');
    this.resource('bar', function(){
      this.route('baz')
    });
  });
  this.route('login');
});

Here's a similar question with a pattern that I'm getting at:

Protecting a route using Firebase Simple Login