Skip to content

Commit

Permalink
Step 5.7: Add routes runner to handle route state change error
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 22, 2016
1 parent 1a2f138 commit b298cc0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from 'angular-ecmascript/module-helpers';
import { _ } from 'meteor/underscore';
import { Config, Runner } from 'angular-ecmascript/module-helpers';

export default class RoutesConfig extends Config {
class RoutesConfig extends Config {
static $inject = ['$stateProvider', '$urlRouterProvider']

constructor() {
Expand Down Expand Up @@ -44,4 +45,20 @@ export default class RoutesConfig extends Config {
isAuthorized($auth) {
return $auth.awaitUser();
}
}
}

class RoutesRunner extends Runner {
static $inject = ['$rootScope', '$state']

run() {
this.$rootScope.$on('$stateChangeError', (...args) => {
const err = _.last(args);

if (err === 'AUTH_REQUIRED') {
this.$state.go('login');
}
});
}
}

export default [RoutesConfig, RoutesRunner];

0 comments on commit b298cc0

Please sign in to comment.