Created
July 22, 2014 15:52
-
-
Save pavloo/cfc4ff41741d43fdb04b to your computer and use it in GitHub Desktop.
Metaprog in Ember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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