Ghost/core/client/routes/authenticated.js
Matt Enlow 49e4403730 Transition user to original destination after signin
Closes #2943
- `AuthenticatedRoute` now stores the user's original destination on the
  `ApplicationController`.
- The `SignIn` route's `login` action checks if the `loginTransition` property is set on the
  `ApplicationController`, and if so, retries that transition after a
  successful login.
2014-06-13 14:28:35 -06:00

25 lines
742 B
JavaScript

var AuthenticatedRoute = Ember.Route.extend({
beforeModel: function (transition) {
var user = this.container.lookup('user:current');
if (!user || !user.get('isSignedIn')) {
this.redirectToSignin(transition);
}
},
redirectToSignin: function (transition) {
this.notifications.showError('Please sign in');
if (transition) {
this.controllerFor('application').set('loginTransition', transition);
}
this.transitionTo('signin');
},
actions: {
error: function (error) {
if (error.jqXHR && error.jqXHR.status === 401) {
this.redirectToSignin();
}
}
}
});
export default AuthenticatedRoute;