I’m trying to solve a basic problem but I cannot seem to figure out how to do this with Ember. How can I prevent access to routes until App.User.loggedIn is set to true?
These are the routes that I have:
App.Router.map(function() {
this.route('login', { path: '/' });
this.route('home');
this.route('settings');
this.route('help');
// ... and some nested routes too
});
I’ve done some basic auth in my Ember app here. The basic premise is to redirect to login on a 401 from the API. Also, if there’s a global authentication_token variable defined or stored in a cookie, sign all requests with it. Not sure if it’s the best approach (I’m not crazy about the jQuery ajax 401 manipulation), but it has been working pretty well.
I like the benburton way but I would also do it using authorization atributes on each request and a correct aproach when “request denied” comes from the server.
On server side you could use an ACL system or something else for each request, declaring resources and types of access (read, write, etc.).