From 77faaf8a3eca7118e367bfb2cafddc96da7e2de6 Mon Sep 17 00:00:00 2001 From: DAB0mB Date: Sun, 3 Apr 2016 00:34:22 +0300 Subject: [PATCH] Step 4.9: Add resolve to auth routes --- client/scripts/routes.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/client/scripts/routes.js b/client/scripts/routes.js index 47f5ff4..06f3008 100644 --- a/client/scripts/routes.js +++ b/client/scripts/routes.js @@ -8,12 +8,21 @@ import profileTemplateUrl from '../templates/profile.html'; import tabsTemplateUrl from '../templates/tabs.html'; export default class RoutesConfig extends Config { + constructor() { + super(...arguments); + + this.isAuthorized = ['$auth', this.isAuthorized.bind(this)]; + } + configure() { this.$stateProvider .state('tab', { url: '/tab', abstract: true, - templateUrl: tabsTemplateUrl + templateUrl: tabsTemplateUrl, + resolve: { + user: this.isAuthorized + } }) .state('tab.chats', { url: '/chats', @@ -46,11 +55,18 @@ export default class RoutesConfig extends Config { .state('profile', { url: '/profile', templateUrl: profileTemplateUrl, - controller: 'ProfileCtrl as profile' + controller: 'ProfileCtrl as profile', + resolve: { + user: this.isAuthorized + } }); this.$urlRouterProvider.otherwise('tab/chats'); } + + isAuthorized($auth) { + return $auth.awaitUser(); + } } RoutesConfig.$inject = ['$stateProvider', '$urlRouterProvider']; \ No newline at end of file