Created
March 7, 2017 10:05
-
-
Save d30jeff/52c12d1553fe55b5be5ecc83b5bec38d to your computer and use it in GitHub Desktop.
Weird Route
This file contains hidden or 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
'use strict'; | |
// Main App | |
angular.module('') | |
.config(function($stateProvider) { | |
$stateProvider | |
.state('dashboard', { | |
resolve: { | |
'Authenticated': function(Auth) { | |
return Auth.loggedIn(); | |
} | |
} | |
}) | |
}) | |
.run(function($rootScope) { | |
$rootScope.$on('$routeChangeStart', function(event, current, previous, rejection) { | |
console.log('x'); | |
if (rejection === 'notLoggedIn') { | |
event.preventDefault(); | |
$location.path('/'); | |
} | |
}) | |
}) | |
// Service | |
angular.module('') | |
.factory('Auth', function($q) { | |
this.loggedIn = function() { | |
if ($cookies.get('token')) { | |
return $q.resolve(); | |
} else { | |
return $q.reject('notLoggedIn'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment