Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created March 7, 2017 10:05
Show Gist options
  • Save d30jeff/52c12d1553fe55b5be5ecc83b5bec38d to your computer and use it in GitHub Desktop.
Save d30jeff/52c12d1553fe55b5be5ecc83b5bec38d to your computer and use it in GitHub Desktop.
Weird Route
'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