Skip to content

Instantly share code, notes, and snippets.

@pavloo
Created July 22, 2014 15:52
Show Gist options
  • Save pavloo/cfc4ff41741d43fdb04b to your computer and use it in GitHub Desktop.
Save pavloo/cfc4ff41741d43fdb04b to your computer and use it in GitHub Desktop.
Metaprog in Ember
Ember.Application.initializer({
name: 'authenticated-routes',
after: 'simple-auth',
initialize: function(container, application) {
var routeNames = Object.keys(Teachertrainingv2.Router.router.recognizer.names),
routeObj = null;
var systemRoutes = ['loading', 'error', 'application'];
var routesWithoutAuth = systemRoutes.concat(Teachertrainingv2.ROUTES_NOT_REQUIRE_AUTHENTICATION);
routeNames.forEach(function(routeName){
// if route not in the list, then we need auth to access it
if (routesWithoutAuth.indexOf(routeName) === -1){
routeObj = container.lookup('route:' + routeName);
if (routeObj){
routeObj.reopen(SimpleAuth.AuthenticatedRouteMixin);
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment