Skip to content

Instantly share code, notes, and snippets.

@romuloctba
Created July 17, 2014 00:32
Show Gist options
  • Save romuloctba/0a9eafd2fe6dd3df5c1e to your computer and use it in GitHub Desktop.
Save romuloctba/0a9eafd2fe6dd3df5c1e to your computer and use it in GitHub Desktop.
Checking for authentication in AngularJS
app.run(function ($location,$rootScope,AuthenticationService, FlashService, $templateCache){
var routesThatRequireAuth = ['/main'];
$rootScope.$on('$stateChangeStart', function(event,next,current){
if(_(routesThatRequireAuth).contains($location.path()) && !AuthenticationService.isLoggedIn()) {
$location.path('/login');
FlashService.info("Por favor efetue login para continuar.");
}
});
});
//by leonardo.frangelli do grupo fb.com/groups/angularjsbrasil/428371040637355/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment