I am using token auth and currently if a user is not signed in they are directed to the url path of '/login', I want to allow users to go to the path '/createUser'. The code below is what directs users to the login page if they are not logged in. How would I allow users to navigate to the '/createUser' path if they are a new user?
angular.module('Demo', [
'ngRoute'
]).run(function(
$rootScope,
$location,
$http,
$window,
AuthFactory,
UserFactory,
TitleFactory,
SkillsFactory
) {
$rootScope.$on('$routeChangeStart', function(event, next) {
console.log(next);
if (AuthFactory.isAuthenticated()) {
$http.defaults.headers.common['Authorization'] = 'Token token=' + $window.sessionStorage.getItem('demo.user');
UserFactory.fetch();
TitleFactory.fetch();
SkillsFactory.fetch();
} else {
$location.path('/login');
}
});
});
Have a look at ui-router, which allows you to create state hierarchy. With state hierarchy you can add a "redirect if not logged in" logic just to your
'authenticated'
state (ancestor of all states requiring authentication) and let the user switch between other states without any trouble.